Quiz Entry - updated: 2026.10.30
What is the syntax of an ad-hoc command, and what does each part mean?
ansible host-pattern -m module [-a 'module arguments'] [-i inventory]: which hosts, which module, the module's arguments as a quoted string, and optionally which inventory.
* Each part of an ad-hoc command answers one question: where, what, how, and from which list. *
- host-pattern: a single managed host, a group, or
all. It is resolved against the inventory, exactly as with--list-hosts. -m module: the module to run on the targets, for exampleping,user,command. Modules are small programs that carry out tasks.-a 'arguments': the module's options as one quoted string, for example'name=newbie uid=4000 state=present'. Some modules (likeping) need none.-i inventory: a different inventory than the one set inansible.cfg.
Example: ansible servera.lab.example.com -m user -a 'name=newbie uid=4000 state=present' makes sure user newbie with UID 4000 exists on servera.
If you leave out -m, Ansible uses the command module by default.
Go deeper:
ansible command reference (official docs) — all options including
-m,-a,-i,-b(become).Introduction to ad hoc commands (official docs) — worked examples per module.