Day 56: Understanding Ad-hoc commands in Ansible

Pooja BhavaniPooja Bhavani
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

Pooja Bhavani
Pooja Bhavani

Hi, I am Pooja Bhavani, an enthusiastic DevOps Engineer with a focus on deploying production-ready applications, infrastructure automation, cloud-native technologies. With hands-on experience across DevOps Tools and AWS Cloud, I thrive on making infrastructure scalable, secure, and efficient. My journey into DevOps has been fueled by curiosity and a passion for solving real-world challenges through automation, cloud architecture, and seamless deployments. I enjoy working on projects that push boundaries whether it's building resilient systems, optimizing CI/CD pipelines, or exploring emerging technologies like Amazon Q and GenAI. I'm currently diving deeper into platform engineering and GitOps workflows, and I often share practical tutorials, insights, and use cases from my projects and experiences. ✨ Let’s connect, collaborate, and grow together in this ever-evolving DevOps world. Open to opportunities, ideas, and conversations that drive impactful tech!