Day 56: Understanding Ad-hoc commands in Ansible
In the ever-evolving landscape of IT automation, Ansible has emerged as a powerful and versatile tool for managing and orchestrating complex infrastructures. On our journey to demystify this automation marvel, we’ve arrived at Day 56, where we delve into the realm of “Ad-hoc commands in Ansible.”
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 handy when you want to perform a quick task.
Tasks
Task 1) Write an ansible ad hoc ping command to ping 3 servers from inventory file
To ping all the servers run below command
ansible -m ping all -i /etc/ansible/hosts
Task 2) Write an ansible ad hoc command to check uptime
To check the uptime run below command
ansible -m command -a “uptime” -i /etc/ansible/hosts all
Task 3) Check the free memory or memory usage of hosts using ansible ad hoc command
To check the memory usage run below
ansible -m command -a “free -m” -i /etc/ansible/hosts all