Table of contents
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.
Task: Realtime examples on Ansible.
write an ansible ad hoc ping command to ping 3 servers from the inventory file
As the task says, we have created 1 master server and 3 node servers and made a connection between them through public keys and integrated in the inventory file.
All of this we have done in my yesterday's blog.
Execute the ping command to ping all the 3 servers by passing inventory as input.
ansible all -m ping -i /etc/ansible/hosts
The output indicates the healthy state of all the 3 node server.
Write an ansible ad hoc command to check uptime
Execute the uptime command for all the servers mentioned in the inventory file.
ansible all -a uptime -i /etc/ansible/hosts
The output indicates the total time for which all the 3 node servers are up and running.
Thanks for reading my article. Have a nice day.
You can follow me on LinkedIn for my daily updates:- linkedin.com/in/bandan-kumar-sahoo-131412203