Skip to main content

Ansible Cheat Sheet 2026 — Quick CLI Command Reference

Ansible Cheat Sheet 2026 — Quick Command Reference

Ansible Cheat Sheet is the complete quick-reference of Ansible commands grouped by function. Copy any command with one click and find what you need with Ctrl+F in under 3 seconds.

Ad-hoc Commands

Action Command Useful flags
List hosts belonging to a group
ansible <group> --list-hosts
--list-hosts
Ping a group of hosts by invoking the ping module
ansible <group> --module-name ping
--module-name
Display facts about a group of hosts by invoking the setup module
ansible <group> --module-name setup
--module-name
Execute a command on a group of hosts by invoking command module with arguments
ansible <group> --module-name command --args '<my_command>'
--module-name --args
Execute a command with administrative privileges
ansible <group> --become --ask-become-pass --module-name command --args '<my_command>'
--become --ask-become-pass --module-name --args
Execute a command using a custom inventory file
ansible <group> --inventory <inventory_file> --module-name command --args '<my_command>'
--inventory --module-name --args
List the groups in an inventory
ansible localhost --module-name debug --args '<var=groups.keys()>'
--module-name --args

Playbooks

Action Command Useful flags
Run tasks in playbook
ansible-playbook <playbook>
Run tasks in playbook with custom host inventory
ansible-playbook <playbook> --inventory <inventory_file>
--inventory
Run tasks in playbook with extra variables defined via the command-line
ansible-playbook <playbook> --extra-vars "<variable1>=<value1> <variable2>=<value2>"
--extra-vars
Run tasks in playbook with extra variables defined in a JSON file
ansible-playbook <playbook> --extra-vars "@<variables.json>"
--extra-vars
Run tasks in playbook for the given tags
ansible-playbook <playbook> --tags <tag1,tag2>
--tags
Run tasks in a playbook starting at a specific task
ansible-playbook <playbook> --start-at <task_name>
--start-at
Run tasks in a playbook without making any changes (dry-run)
ansible-playbook <playbook> --check --diff
--check --diff

⚠️ Dangerous / Destructive Commands

These commands are irreversible. Verify your environment (dev/staging vs prod) before running them.

Action Command Warning
⚠️ Destroy ⚠️
terraform destroy -auto-approve
Irreversible — verify the target before running
⚠️ Delete
kubectl delete namespace production
Irreversible — verify the target before running
⚠️ Prune ⚠️
docker system prune -af --volumes
Irreversible — verify the target before running
⚠️ Delete
pvesh delete /nodes/{node}/qemu/{vmid}
Irreversible — verify the target before running
⚠️ Delete
az group delete --name MyResourceGroup --yes
Irreversible — verify the target before running

FAQ — Frequently Asked Questions

What is the difference between Ad-hoc Commands and Playbooks?

Each group in this Ansible cheat sheet covers a distinct area. Ad-hoc Commands focuses on its specific scope, while Playbooks and the remaining groups cover networking, storage, security and diagnostics respectively.

How do I check the installed Ansible version?

Run the version command (usually ansible version or ansible --version). The output shows the client and, when applicable, the server version.

Why does Ansible return ‘permission denied’?

A ‘permission denied’ error in Ansible usually means the current user lacks sufficient privileges or credentials are not configured. Check: (1) assigned IAM/RBAC roles, (2) an active authentication context via the corresponding login command.

How do I filter Ansible output by status or name?

Use flags such as --filter, --selector or --query depending on the tool. You can also pipe into grep or jq to process JSON:

ansible list | grep RUNNING

What is the fastest way to debug a Ansible error?

Add the verbose flag (--verbose, -v or --debug) to the failing command. This reveals the underlying HTTP/API calls and the full error response body.

Official sources & references

Commands cross-checked against vendor documentation and high-authority repositories: