📦 Core Commands
| Command | Description | Example |
|---|---|---|
ansible | Run ad-hoc commands with modules | ansible all -i inventory.yaml -m ping |
ansible-playbook | Execute a playbook | ansible-playbook -i inventory.yaml site.yaml |
ansible-doc | View module or plugin documentation | ansible-doc copy |
ansible-config | Display current configuration | ansible-config list |
ansible-inventory | Inspect or validate your inventory | ansible-inventory -i inventory.yaml --list |
ansible-vault | Encrypt/decrypt sensitive files | ansible-vault encrypt secrets.yaml |
ansible-galaxy | Manage roles and collections | ansible-galaxy collection install community.general |
⚡ Common Ad-Hoc Commands
| Purpose | Command |
|---|---|
| Ping all hosts | ansible all -m ping |
| Run shell command | ansible all -m shell -a "uptime" |
| Restart nginx service | ansible webservers -m service -a "name=nginx state=restarted" |
| Copy file to hosts | ansible all -m copy -a "src=./file.conf dest=/etc/file.conf" |
| Execute a script | ansible all -m script -a "./install.sh" |
📘 Playbook Options
| Purpose | Command |
|---|---|
| Run a playbook | ansible-playbook -i inventory.yaml setup.yaml |
| Use extra vars file | ansible-playbook site.yaml --extra-vars "@vars.yaml" |
| Dry run (check mode) | ansible-playbook site.yaml --check |
| Limit to specific host | ansible-playbook site.yaml --limit "web01" |
| Show file diff | ansible-playbook site.yaml --diff |
🔐 Vault Commands
| Purpose | Command |
|---|---|
| Encrypt a file | ansible-vault encrypt secrets.yaml |
| Decrypt a file | ansible-vault decrypt secrets.yaml |
| Edit encrypted file | ansible-vault edit secrets.yaml |
| View encrypted file | ansible-vault view secrets.yaml |
🧰 Galaxy Commands
| Purpose | Command |
|---|---|
| Install a role | ansible-galaxy install geerlingguy.docker |
| Install a collection | ansible-galaxy collection install community.general |
| Initialize a role |

