Day 56: Understanding Ad-hoc commands in Ansible

2 min read
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 handy when you want to perform a quick task.
Task-01
write an ansible ad hoc ping command to ping 3 servers from inventory file
Write an ansible ad hoc command to check uptime
- It will show an error because it doesn’t have the Ansible SSH private key. You can verify this using the inventory command.
ansible-inventory --list
- Execute this command to solve your error
ansible all -m ping
Write an ansible ad hoc command to check your date , time and uptime
- Now you can see date time and update or install your 'all' servers using these commands.
ansible all -a "free -h"
ansible all -a "date"
ansible all -a "sudo apt-get update"
ansible all -a "sudo apt-get install nginx -y"
ansible all -a "dh -h"
ansible all -a "free -h"
ansible all -a "uptime"
0
Subscribe to my newsletter
Read articles from Pooja Bhavani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
