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 |
|
--list-hosts |
| Ping a group of hosts by invoking the ping module |
|
--module-name |
| Display facts about a group of hosts by invoking the setup module |
|
--module-name |
| Execute a command on a group of hosts by invoking command module with arguments |
|
--module-name --args |
| Execute a command with administrative privileges |
|
--become --ask-become-pass --module-name --args |
| Execute a command using a custom inventory file |
|
--inventory --module-name --args |
| List the groups in an inventory |
|
--module-name --args |
Playbooks
| Action | Command | Useful flags |
|---|---|---|
| Run tasks in playbook |
|
|
| Run tasks in playbook with custom host inventory |
|
--inventory |
| Run tasks in playbook with extra variables defined via the command-line |
|
--extra-vars |
| Run tasks in playbook with extra variables defined in a JSON file |
|
--extra-vars |
| Run tasks in playbook for the given tags |
|
--tags |
| Run tasks in a playbook starting at a specific task |
|
--start-at |
| Run tasks in a playbook without making any changes (dry-run) |
|
--check --diff |
⚠️ Dangerous / Destructive Commands
These commands are irreversible. Verify your environment (dev/staging vs prod) before running them.
| Action | Command | Warning |
|---|---|---|
| ⚠️ Destroy ⚠️ |
|
Irreversible — verify the target before running |
| ⚠️ Delete |
|
Irreversible — verify the target before running |
| ⚠️ Prune ⚠️ |
|
Irreversible — verify the target before running |
| ⚠️ Delete |
|
Irreversible — verify the target before running |
| ⚠️ Delete |
|
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: