Anatomy of the ansible Command
Read the -m, -a and pattern arguments.
Anatomy of the ansible Command is a free Ansible Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
One Command, Many Servers
An ad-hoc command runs a single task across your servers right now, with no playbook file to write first. 🚀
Meet the ansible Command
You start every ad-hoc run with the ansible binary, followed by a host pattern and the options that say what to do.
ansible all -m pingThe Host Pattern Comes First
The first word after ansible is the host pattern: it picks which inventory hosts the command will touch.
ansible web -m ping-m Chooses the Module
The -m flag names the module to run. Without it, Ansible falls back to the default command module.
ansible all -m setup-a Passes Arguments
The -a flag passes arguments to the chosen module, wrapped in quotes when they contain spaces.
ansible all -m shell -a "uptime"Point at Your Inventory
Use -i to tell Ansible which inventory file lists your hosts, instead of relying on the default location.
ansible all -i hosts.ini -m pingChoose the Remote User
The -u flag sets the SSH user Ansible logs in as, overriding the current local username.
ansible web -u deploy -m pingPutting the Pieces Together
A full ad-hoc command reads as: ansible pattern, then -m module, then -a arguments. That order is the whole anatomy.
ansible db -m service -a "name=postgresql state=started"Increase Output Detail
Add -v for more output when something looks off. Stack more v's, like -vvv, for deeper debugging detail.
ansible all -m ping -vvvAd-Hoc vs Playbook
An ad-hoc command is great for quick, one-off checks. For anything you repeat, you graduate to a saved playbook.
Default Module Is command
If you skip -m entirely, Ansible runs the command module on your arguments, so a bare run still does something useful.
ansible all -a "hostname"Quick Check
Which flag tells the ansible command which module to use?
Recap
You can now read an ansible command: pattern picks hosts, -m picks the module, -a passes its arguments. Nice work! 🎉
Frequently asked questions
Is the “Anatomy of the ansible Command” lesson free?
Yes — the full text of “Anatomy of the ansible Command” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.
What will I learn in “Anatomy of the ansible Command”?
Read the -m, -a and pattern arguments. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ansible Academy?
No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Anatomy of the ansible Command” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ansible Academy lesson?
Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Anatomy of the ansible Command
- Patterns: Targeting all, web & host1
- Run Shell Commands with command & shell
- Privilege Escalation with become