Quiz Entry - updated: 2026.10.30
What is an ad-hoc command, and when is it the right tool instead of a playbook?
A one-line ansible command that runs a single task (one module) against a set of hosts without writing a playbook. It is right for quick tests, checks and one-off changes; repeatable, multi-step work belongs in a playbook.
Typical good uses:
- check that all hosts are reachable (
ansible all -m ping); - make sure a line is present in
/etc/hostson a group of servers; - restart a service on many machines at once;
- make sure one package is up to date everywhere.
Ad-hoc commands use the same modules, inventory and idempotency as playbooks, so they are safe and fast. Their limit is that each one is one task, run once, and then gone: no ordering of several steps, no record in Git, nothing a colleague can rerun exactly. As soon as you would run the same thing again or chain steps, write a playbook, which stores the sequence in a readable, versionable, repeatable form.
Go deeper:
Introduction to ad hoc commands (official docs) — use cases: rebooting, managing files, packages, users and services.
Ansible 101 - Episode 2 - Ad-hoc tasks and Inventory (Jeff Geerling) — ad-hoc commands against a small server fleet.