Understanding Ad-hoc commands in Ansible
1 min read
Ansible ad hoc commands are one-liners designed to achieve a particular 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 are handy when you want to perform a quick task.
Task-01
write an ansible ad hoc ping command to ping multiple servers from the inventory file
#before that either you cd to hosts folder or add full path to the command ansible -i /home/ubuntu/hosts -m ping --private-key=~/.ssh/ansible_key
ansible all -a "free -h" -i hosts --private-key=~/.shh/ansible_key
the above command will show you the disk space utilized in node servers.
Write an ansible ad hoc command to check uptime.
ansible servers -a "uptime" hosts --private-key=~/.ssh/ansible_key
The above command will show you the time since the server is running the tasks.
happy Learning!!๐