Commands
Ansible
ansible all -a "whoami"Execute command on all hosts specified in inventory file.
ansible all -m pingExecute a module on all hosts.
ansible all -m ansible.builtin.setup -a "filter=ansible_os_family"Return the
ansible_os_family
Ansible fact.
Playbook
ansible-playbook myPlaybook.ymlExecute a playbook.
Inventory
ansible-inventory -i myHostsFile --listList hosts in the inventory.
ansible-inventory -i myHostsFile --list --yaml --output myHostsFile.ymlConvert inventory file format form INI to YAML.
Vault
ansible-vault create secret.ymlCreate a secure file (secured by password) to store secrets.
ansible-vault edit secret.ymlEdit the secure file.
Flags
Variables
-e ansible_python_interpreter=/usr/bin/python3Set additional variable.
Inventory
-i myHostsFileSpecify inventory file to use.
-i "192.168.1.1,"Specify a host inline.
-i "localhost," --connection=localRun on localhost.
User
-u myUserSpecify the user to use for remote connection.
--becomeUse sudo when executing commands.
Passwords
-kPrompt user to enter SSH password (
--ask-pass
).-KPrompt user to enter Become password (
--ask-become-pass
).-JPrompt user to enter Secure Variables's Vault password (
--ask-vault-pass
).
Misc
-CDry run, show expected output of playbook (
--check
).
-DShow details of the changes (
--diff
).