Give practical use cases for ad-hoc commands.
IntermediateConceptAd-hoc Commands, Modules and Idempotency
Answer
- Check connectivity or uptime across the fleet.
- Restart a service everywhere during an incident.
- Check disk or memory quickly:
ansible all -m shell -a "df -h /". - Push a hotfix file:
ansible web -m copy -a "src=app.conf dest=/etc/app.conf" -b. - Gather facts of one host to inspect them:
-m setup. - Install a package on a few hosts.
Because these are not recorded in version control, we reserve them for diagnostics and break-glass fixes and then codify real changes in a playbook.
More on Ad-hoc Commands, Modules and Idempotency
What is an ad-hoc command and what is its syntax?BeginnerWhat does `ansible all -m ping` actually test?BeginnerWhat 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