Ansible Command Cheat Sheet

📦 Core Commands

CommandDescriptionExample
ansibleRun ad-hoc commands with modulesansible all -i inventory.yaml -m ping
ansible-playbookExecute a playbookansible-playbook -i inventory.yaml site.yaml
ansible-docView module or plugin documentationansible-doc copy
ansible-configDisplay current configurationansible-config list
ansible-inventoryInspect or validate your inventoryansible-inventory -i inventory.yaml --list
ansible-vaultEncrypt/decrypt sensitive filesansible-vault encrypt secrets.yaml
ansible-galaxyManage roles and collectionsansible-galaxy collection install community.general

⚡ Common Ad-Hoc Commands

PurposeCommand
Ping all hostsansible all -m ping
Run shell commandansible all -m shell -a "uptime"
Restart nginx serviceansible webservers -m service -a "name=nginx state=restarted"
Copy file to hostsansible all -m copy -a "src=./file.conf dest=/etc/file.conf"
Execute a scriptansible all -m script -a "./install.sh"

📘 Playbook Options

PurposeCommand
Run a playbookansible-playbook -i inventory.yaml setup.yaml
Use extra vars fileansible-playbook site.yaml --extra-vars "@vars.yaml"
Dry run (check mode)ansible-playbook site.yaml --check
Limit to specific hostansible-playbook site.yaml --limit "web01"
Show file diffansible-playbook site.yaml --diff

🔐 Vault Commands

PurposeCommand
Encrypt a fileansible-vault encrypt secrets.yaml
Decrypt a fileansible-vault decrypt secrets.yaml
Edit encrypted fileansible-vault edit secrets.yaml
View encrypted fileansible-vault view secrets.yaml

🧰 Galaxy Commands

PurposeCommand
Install a roleansible-galaxy install geerlingguy.docker
Install a collectionansible-galaxy collection install community.general
Initialize a role