ansible命令中的`args`部分是什么

Sno*_*ash 7 ansible

此示例仅在/ 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
Run Code Online (Sandbox Code Playgroud)

但为什么它列在args:

那是什么args:设置?

Kon*_*rov 10

args用于将命名参数显式传递给支持"自由格式"参数的操作 - args需要额外的单词,因为在YAML(用于Ansible playbooks的语言)中,您无法为字典的"root"键分配字符串值.

# here `command` is a string
command: /bin/echo ok

# here `user` is a dict
user:
  name: john
Run Code Online (Sandbox Code Playgroud)

而且由于command是一个字符串,可以使用args通过额外的参数(如chdir,creates等).虽然user是一个字典,这样你就可以直接在里面添加参数(如name,uid等).