šŸ› ļø Day 56: Getting Hands-On with Ad-hoc Commands in Ansible!

Ā·

2 min read

Today, letā€™s dive into the world of Ansible Ad-hoc Commands, the ultimate time-savers for quick tasks. Whether you want to check server connectivity or grab some system info, these one-liners will do the trick. Think of ad-hoc commands as quick Linux commands, while playbooks are like fully-fledged shell scripts loaded with logic.

Letā€™s explore some practical tasks with these handy commands. šŸ› ļø


šŸš€ Task 1: Ping 3 Servers from the Inventory File

First things first, letā€™s check if our servers are alive and kicking! Hereā€™s the command youā€™ll use:

ansible all -m ping

Hereā€™s the magic behind it:

  • all: This targets all the hosts listed in your inventory file.

  • -m ping: The ping module sends a quick ping to ensure your servers are reachable.

Run this! Your servers will respond, confirming theyā€™re ready for action.


ā± Task 2: Check Uptime of Servers

Curious about how long your servers have been running? This ad-hoc command has your back:

ansible all -a "uptime"

Hereā€™s the breakdown:

  • all: Targets all hosts again.

  • -a "uptime": Executes the Linux uptime command to show how long each server has been up and running.

Simple, right? And super useful when youā€™re monitoring system performance.


šŸ”§ Other Ad-hoc Commands to Try

Why stop here? Check out these other quick tasks you can perform with ad-hoc commands:

  • Check disk space:

      ansible all -a "df -h"
    
  • Fetch the current date and time:

      ansible all -a "date"
    
  • Reboot all servers (use with caution!):

      ansible all -a "reboot" --become
    


Final Thoughts

Ansible Ad-hoc Commands are like the espresso shots of automationā€”quick, effective, and energizing. With just one line, you can perform powerful tasks across multiple machines. Isnā€™t that amazing?

Keep experimenting, keep learning, and rememberā€”every little step takes you closer to becoming a DevOps pro! šŸš€

Until next time, happy automating! šŸ˜Š

Ā