What is an ad-hoc command and what is its syntax?
BeginnerConceptAd-hoc Commands, Modules and Idempotency
Answer
An ad-hoc command runs a single module against hosts from the command line, with nothing saved. Syntax: ansible <pattern> -m <module> -a "<args>" [options].
ansible web -m ansible.builtin.ping
ansible web -m ansible.builtin.service -a "name=nginx state=restarted" -b
ansible all -a "uptime" # default module is command
ansible db -m ansible.builtin.setup -a "filter=ansible_mem*"
Good for one-off checks and emergencies. Anything you will do twice belongs in a playbook.
More on Ad-hoc Commands, Modules and Idempotency
What does `ansible all -m ping` actually test?BeginnerGive practical use cases for ad-hoc commands.IntermediateWhat is the difference between the `command` and `shell` modules?BeginnerCompare `raw`, `command`, `shell` and `script`.IntermediateWhy prefer a dedicated module over `shell`/`command`?BeginnerWhat is idempotency and why does it matter?Beginner