ansible常用模块

ansible 核心模块之 command

2020-12-14  本文已影响0人  wh0am11

command模块

command 模块用于在远程主机上执行命令

参数 (=号后面的参数强制要求):

在执行对应的命令之前,会先进入到此参数指定的目录中
[Default: (null)]
version_added: 0.6

当指定的文件存在时,就不执行对应命令
[Default: (null)]

当指定的文件不存在时,就不执行对应命令
[Default: (null)]
version_added: 0.8

必须参数,指定需要远程执行的命令,但是并没有具体的一个参数名叫 free_form

注意:

区别:

实例:

- name: return motd to registered var
  command: cat /etc/motd
  register: mymotd

- name: Run the command if the specified file does not exist.
  command: /usr/bin/make_database.sh arg1 arg2
  args:
    creates: /path/to/database

# You can also use the 'args' form to provide the options.
- name: This command will change the working directory to somedir/ and will only run when /path/to/database doesn't exist.
  command: /usr/bin/make_database.sh arg1 arg2
  args:
    chdir: somedir/
    creates: /path/to/database

- name: use argv to send the command as a list.  Be sure to leave command empty
  command:
  args:
    argv:
      - echo
      - testing

- name: safely use templated variable to run command. Always use the quote filter to avoid injection issues.
  command: cat {{ myfile|quote }}
  register: myoutput
上一篇 下一篇

猜你喜欢

热点阅读