Ansible CLI & Playbook Commands Cheat Sheet
Production Ansible CLI reference matrix covering ping, ad-hoc execution, playbook check mode, tags, vault encryption, and inventory graphs with 1-click copy.
Ad-Hoc & Connectivity (4 commands)
ansible all -m ping
Tests SSH connectivity and Python availability across all inventory managed nodes.
ansible webservers -m setup -a "filter=ansible_distribution*"
Gathers hardware, OS distribution, memory, and IP facts from the webservers group.
ansible all -m command -a "uptime" -o
Runs the uptime command across all nodes and outputs responses in a concise single-line format (-o).
ansible dbservers -m shell -a "free -m | grep Mem" -b
Executes shell command with administrative privileges (sudo) via the become flag (-b).
Playbook Execution (5 commands)
ansible-playbook site.yml --check --diff
Executes dry-run audit mode without modifying remote state and displays unified diff of pending changes.
ansible-playbook deploy.yml -i production.ini --limit webservers
Applies playbook against a specific custom inventory file and restricts tasks to the webservers group.
ansible-playbook site.yml --tags "nginx,ssl" --skip-tags "backup"
Selectively executes only tasks marked with specified tags while skipping lengthy backup routines.
ansible-playbook site.yml --start-at-task="Restart Nginx Service"
Resumes a failed playbook directly at a specific named task without re-running earlier completed steps.
ansible-playbook site.yml --step
Prompts for interactive user confirmation before executing each individual playbook task.
Inventory Management (2 commands)
ansible-inventory -i hosts.yml --graph
Displays a visual ASCII hierarchical tree of all inventory groups and child nodes.
ansible-inventory -i hosts.yml --list
Outputs inventory hosts, groups, and assigned hostvars in formatted machine-readable JSON.
Secrets & Vault (4 commands)
ansible-vault create vars/vault.yml
Creates a new AES-256 encrypted YAML file for storing database passwords and API tokens.
ansible-vault edit vars/vault.yml
Decrypts, opens vault file in $EDITOR (e.g. vim or nano), and re-encrypts upon file save.
ansible-vault encrypt_string "MySecretPassword123" --name "db_password"
Encrypts a single variable string inline for embedding directly into plaintext variable files.
ansible-playbook site.yml --vault-password-file ~/.vault_pass
Supplies vault decryption key from a protected local file, avoiding interactive password prompts.
Galaxy & Roles (2 commands)
ansible-galaxy install geerlingguy.nginx
Downloads and installs community-tested production roles from Ansible Galaxy.
ansible-galaxy role init my_custom_role
Scaffolds standard Ansible role directory layout (tasks, handlers, defaults, vars, meta).