How to specify multiple arguments ( MODULE_ARGS ) to ansible command

I wanna execute ansible command like this playbook.
- hosts: localhost
  tasks:
    - file:
        path: ~/example.txt
        state: touch

Answer

I found, I can specify args key/value format separated with spaces,.

$ ansible -m [module_name] --args "key1=value2 key2=value2"

Example

$ ansible localhost -m "file" --args "path=~/example.txt state=touch" 
localhost | SUCCESS => {
    "changed": true,
    "dest": "/Users/yinaura/example.txt",
    "gid": 20,
    "group": "staff",
    "mode": "0644",
    "owner": "yinaura",
    "size": 4,
    "state": "file",
    "uid": 501
}


BTW

ansible help is toooooooo simple, God!

Options:
  -a MODULE_ARGS, --args=MODULE_ARGS
                        module arguments

 

Version

  • ansible 2.6.0