Commands
Ansible
ansible all -a "whoami"
Execute command on all hosts specified in inventory file.
ansible all -m ping
Execute a module on all hosts.ansible all -m ansible.builtin.setup -a "filter=ansible_os_family"
Return theansible_os_familyAnsible fact.
Playbook
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
Variables
-e ansible_python_interpreter=/usr/bin/python3
Set additional variable.
Inventory
-i myHostsFile
Specify inventory file to use.
-i "192.168.1.1,"
Specify a host inline.-i "localhost," --connection=local
Run on localhost.
User
-u myUser
Specify the user to use for remote connection.--become
Use sudo when executing commands.
Passwords
-k
Prompt user to enter SSH password (--ask-pass).-K
Prompt user to enter Become password (--ask-become-pass).-J
Prompt user to enter Secure Variables's Vault password (--ask-vault-pass).
Misc
-C
Dry run, show expected output of playbook (--check).
-D
Show details of the changes (--diff).
