Skip to main content

Command Palette

Search for a command to run...

Day 56: Understanding Ad-hoc commands in Ansible (Jan 21, 2024)

Updated
1 min read
Day 56: Understanding Ad-hoc commands in Ansible  (Jan 21, 2024)

🙏 Introduction:

In this blog, we'll explore Ansible Ad-hoc commands.

🔶What is Ad-hoc commands in Ansible

  • 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: 1

  1. Write an ansible ad hoc ping command to ping 3 servers from inventory file

  • Create one master node server and three server nodes.

  • Edit the host file
[servers]
host_1 ansible_host=54.184.85.99
host_2 ansible_host=54.200.206.23
host_3 ansible_host=34.215.56.203

[all:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_user=ubuntu
ansible_ssh_private_key_file=/home/ubuntu/keys/ansible-key.pem

  • To verify the inventory of hosts
ansible-inventory --list

  • ad hoc command to ping 3 servers from inventory file
ansible host_1:host_2:host_3 -m ping

  1. Write an ansible ad hoc command to check uptime

ansible -a "uptime" servers

For more Ansible ad-hoc commands we can refer to this link

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.