HomeAutomation Tools

Part #2 : Getting Started with Ansible Ad-Hoc Commands

Part #2 : Getting Started with Ansible Ad-Hoc Commands
Like Tweet Pin it Share Share Email
1x1.trans - Part #2 : Getting Started with Ansible Ad-Hoc Commands

This article is a continuation of Ansible Tutorials, In the previous article, I have talked about Ansible Ad-Hoc Commands. Here I am going to show you some basic commands which help you to get more familiar with Ansible Ad-Hoc Commands. In this guide, you will learn about running quick Ad-Hoc commands to build the web server without writing a playbook. So let’s get started with learning more  Ansible Ad-Hoc Commands.1x1.trans - Part #2 : Getting Started with Ansible Ad-Hoc Commands

Suggestable Read:

1. Introduction and Installation & Configuration of Ansible 2.3 on CentOS/Redhat Linux 7

2. Configuring Ansible Dynamic Inventory for AWS EC2

3. Creating an Ansible static inventory with variables

LAB #1:  Using shell module with filtering the “stings” from the standard out and run the multiple shell commands.

The Shell module will work in Unix/Linux based system to do all kind of tasks which you can perform on locally. Using Ansible Shell Module, almost you can do all the operations on remote servers. But the real fun is using deferent modules to do different tasks.

Task -1:  Check the Filesystem Disk space usage on the target server (ansible-client2) using shell Module. and get the output of only /boot mount point.

Using Shell module to check the file system disk space usage on the target servers.

The above command will show the file system disk space usage on the target server.


Now the task is to grep the specific “string”. The below command will filter /book from the standard output of df –Th.

Note: this operation is not supported by “Command Module

Task -2 Running multiple shell command from ansible Servers using a semicolon (;).


LAB #2: 
Using Ansible commands, complete the following tasks:
1. Test Ansible connection to all your hosts using ping module
2. Install EPEL repo on all your hosts
3. Install HTTPD only on your “web server” hosts using yum module.
4. Change SELINUX to permissive mode on webserver
5. Start and enable the HTTPD Service on “web server”

Results: Get Hands-on Practice.

1. The below Ad-Hoc command (ping module) will test the connectivity of all the remote servers.


2. Installing the EPEL repo on all the servers using “yum module“. Click the Hyperlink to know more about yum module.



3. Installing the HTTPD PACKAGE using “yum module” on “webserver” group.


4. Changing the SELINUX status to permissive mode using selinux Module








5. Starting and Enabling the HTTPD service using Service Module“.

Result: screenshot for reference.

Output Colors:  when you execute Ansible commands/playbooks, will get the status output with below colors. Please check the below details to understand the Command excution status.
#highlight = white
#verbose = blue
#warn = bright purple
#error = red
#debug = dark gray
#deprecate = purple
#skip = cyan
#unreachable = red
#ok = green
#changed = yellow
#diff_add = green
#diff_remove = red
#diff_lines = cyan

1x1.trans - Part #2 : Getting Started with Ansible Ad-Hoc Commands


Output: Testing web page of the Web server.1x1.trans - Part #2 : Getting Started with Ansible Ad-Hoc Commands


Conclusion: that’s all about Ansible Ad-Hoc Commands. I hope you’re enjoying to read more about Ansible automation. Follow our next article to get started with the introduction to Playbooks and how to write a playbook to make simple automation.

If it helps you or if you want to suggest something on this please do comment on below. I will accept your feedback. Happy Automation with Ansible.

Follow our Youtube Channel for more about Ansible Tutorials :

Check out the below Video for More details about Ansible Basics and Ad-Hoc Commands.

[su_youtube_advanced url=”https://www.youtube.com/watch?v=lRwGkO3PtB8″]


Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.