CLI


Basis

ansible all -m ping
Check if all hosts (specified in the inventory file) are reachable.

ansible myHosts -a "whoami"
Execute command on myHosts (specified in the inventory file).

ansible-playbook myPlaybook.yml
Execute a playbook.


Inventory

ansible-inventory -i myHostsFile --list
List hosts in the inventory.

ansible-inventory -i myHostsFile --list --yaml --output myHostsFile.yml
Convert inventory file format form INI to YAML.


Vault

ansible-vault create secret.yml
Create a secure file (secured by password) to store secrets.

ansible-vault edit secret.yml
Edit the secure file.


Flags

-i
Specify inventory file to use.

-u myUser
Execute command as myUser.

-k
Prompt user to enter SSH password.

--become
Use sudo when executing commands.

-K
Prompt user to enter Become password.

---ask-vault-pass
Prompt user to enter Secure Variables's Vault password.

-c
Show expected output of playbook (--check).

-d
Show details of the changes (--diff).