LOGBOOK

HELP

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.

Ad-hoc command split into its four parts: host-pattern selects hosts, -m names the module, -a passes the quoted arguments, -i chooses the 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 example ping, 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 (like ping) need none.
  • -i inventory: a different inventory than the one set in ansible.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:

From Quiz: ITIA / Ansible Inventory, Configuration and Playbooks | Updated: Oct 30, 2026