Ansible Ad-hoc Command

Michael Mensah
3 min readMay 3, 2023

--

What is Ansible Ad-hoc command — Is a one-line commands that are used to perform quick tasks on remote hosts without the need to create a playbook or execute a script.

The purpose of the mini project is to demonstrate how to execute Ad-hoc commands in Ansible.

First — Create your ansible control engine and 3 target servers

Second —To configure the Ansible control engine, add the IP addresses of all three servers to the hosts directory.

Amazon Linux 2  AMI
Install Ansible using command -
Amazon-linux-extras install ansible2 -y
cd /etc/ansible/
ls -l
vi hosts - (Copy and paste all your targer server IP address to the host file)
Shift + : on your keyboard - wq to save your entry in the vim editor

Third — After testing and logging in to all three target servers, you can use the Ad-hoc come to install httpd on all of target server from the Ansible control engine by executing the following command below.

(Command to install httpd)
ansible -m command -a "yum install httpd -y" dev

(Commmand to start httpd)
ansible -m command -a "systemctl start httpd" dev

Four —After running the installation command on the Ansible control engine on all three target servers, the output will depend on the command that was executed.

In conclusion, this is how to set up Ansible to manage configuration across three or more targets servers.

Thank you all for stopping by to read my Mini project with MensahCloud.

--

--

Michael Mensah
Michael Mensah

Written by Michael Mensah

Cloud Systems Engineer | DevOps Engineer

No responses yet