Ansible ad hoc commands are one-liners designed to achieve a very specific task they are like quick snippets and your compact Swiss army knife when you want to do a quick task across multiple machines.
To put simply, Ansible ad hoc commands are one-liner Linux shell commands and playbooks are like a shell script, a collective of many commands with logic.
Ansible ad hoc commands come in handy when you want to perform a quick task.
Refer ansible notes
Refer ansible video
To check the uptime on your local machine
ansible localhost -m command -a "uptime"
To ping your local machine
ansible localhost -m ping
Ansible ad hoc command to check the free RAM or memory usage of hosts.
ansible localhost -m command -a "free -h"
Write an ansible ad hoc command to check the disk space on all hosts in an inventory file.
ansible localhost -m command -a "df -h"
Write an ansible ad hoc command to list all the running processes on a specific host in an inventory file.
ansible localhost -m command -a "df -h"
ansible localhost -m command -a "ps aux"
Thank you so much for reading
Follow me on LinkedIn to see interesting posts like this : )