Connection
ansible -i hosts.ini all -m ping
Test connectivity to all hosts defined in the inventory file
ansible-playbook -i hosts.ini playbook.yml
Run a playbook on hosts defined in the inventory file
ansible host -m setup
Gather facts about a specific host
ansible-playbook playbook.yml --limit host
Run a playbook on a specific host
Ad-hoc Commands
ansible all -m command -a 'uptime'
Run the uptime command on all hosts
ansible all -m shell -a 'ls -la /var/log'
Run a shell command on all hosts
ansible all -m copy -a 'src=/local/path dest=/remote/path'
Copy a file to all hosts
ansible all -m file -a 'path=/remote/path state=absent'
Delete a file on all hosts
ansible all -m apt -a 'name=nginx state=present'
Install nginx on Debian/Ubuntu hosts
Playbook Execution
ansible-playbook playbook.yml
Run a playbook
ansible-playbook playbook.yml --check
Perform a dry run without making changes
ansible-playbook playbook.yml --diff
Show differences in changed files
ansible-playbook playbook.yml --tags=tag1,tag2
Run only tasks with specific tags
ansible-playbook playbook.yml --skip-tags=tag1,tag2
Skip tasks with specific tags
ansible-playbook playbook.yml -v
Run with verbose output (-v, -vv, -vvv for more verbosity)
Inventory Management
ansible-inventory --list
List all hosts in inventory
ansible-inventory --graph
Show inventory hosts as a graph
ansible-inventory --host=hostname
Show variables for a specific host
Vault Operations
ansible-vault create file.yml
Create a new encrypted file
ansible-vault edit file.yml
Edit an encrypted file
ansible-vault encrypt file.yml
Encrypt an existing file
ansible-vault decrypt file.yml
Decrypt an encrypted file
ansible-playbook playbook.yml --ask-vault-pass
Run a playbook and prompt for vault password
Troubleshooting
ansible-playbook playbook.yml --syntax-check
Check playbook syntax
ansible-playbook playbook.yml --step
Run playbook step by step
ansible-config dump
Show Ansible configuration
ansible-doc -l
List all available modules
ansible-doc module_name
Get help for a specific module