Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the `args` section in an ansible command

Tags:

ansible

This example only runs when /path/to/database doesn't exist:

# 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

but why is it listed under args:?

And what's the args: setting for?

like image 481
Snowcrash Avatar asked Jul 17 '17 19:07

Snowcrash


1 Answers

args is used to explicitly pass named parameters to actions that support "free form" parameter – additional word args is required because in YAML (language used for Ansible playbooks) you can't assign string value for "root" key of a dictionary.

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

# here `user` is a dict
user:
  name: john

And because command is a string, you use args to pass additional parameters (like chdir, creates, etc). Whereas user is a dict, so you can add parameters straight in there (like name, uid, etc).

like image 91
Konstantin Suvorov Avatar answered Sep 27 '22 18:09

Konstantin Suvorov