cheatsheet
Ansible Commands Cheatsheet
Quick reference for Ansible commands - inventory, playbooks, and common operations.
Published: December 4, 2024
Ansible Commands Cheatsheet
Ansible is an automation tool for configuration management, application deployment, and task automation.
Inventory
List Dynamic Inventory
ansible-inventory -i <inventory-path> --list
Playbooks
Run a Playbook
ansible-playbook -i <inventory-path> <playbook>.yml -t <tag> --user=<user>
Common Options
| Option | Description |
|---|---|
-i | Specify inventory file |
-t | Run only tagged tasks |
--user | SSH user |
-v, -vv, -vvv | Verbosity levels |
--check | Dry run (don’t make changes) |
--diff | Show differences |
-e | Extra variables |
Quick Reference
| Task | Command |
|---|---|
| List inventory | ansible-inventory -i inv --list |
| Run playbook | ansible-playbook -i inv playbook.yml |
| Dry run | ansible-playbook --check playbook.yml |
| Single task | ansible all -m ping -i inv |
| Ad-hoc command | ansible all -a "uptime" -i inv |
Ad-Hoc Commands
# Ping all hosts
ansible all -m ping -i inventory
# Run shell command
ansible all -a "df -h" -i inventory
# Copy file
ansible all -m copy -a "src=/local/file dest=/remote/file" -i inventory
# Install package
ansible all -m apt -a "name=nginx state=present" -i inventory
Tags
ansibledevopsautomationconfiguration-management