Ansible Playbook which will dynamically load the variable file named same as OS_name and just by using the variable names we can Configure our target node..!!

Shrishti Kapoor
3 min readApr 3, 2021

DESCRIPTION:

Creating an Ansible Playbook which will dynamically load the variable file named same as OS_name and just by using the variable names we can Configure our target node.(Note: Without Using when keyword here)

To do this task Let’s take A Redhat VM as Managed Node and 2 instances as Target Nodes. Here the Target Nodes are Ubuntu and Redhat.

Now Checking the IP’s of Both the Instances.

UBUNTU:

REDHAT:

Now in Managed Node Checking the Configuration file of ansible.

Now in Managed Node Checking the inventory file and Writing the playbook as main.yml.

Now checking the RedHat-8.yml file which is the vars file.

Checking the Ubuntu-20.yml file which is the vars file.

Now checking the index.html file.

Now Running the playbook by using command ansible-playbook main.yml

After running the playbook check both the instances that the services are running or not.

Redhat Instance

Check by using systemctl status httpd.

Inside /var/www/html there is the file index.html which means the page can be run successfully now.

Ubuntu Instance

Checking the Services. In case of Ubuntu the service name is apache2 so checking by using command systemctl status apache2.

Now finally we can also verify for checking that the services run successfully by using the ip/index.html on browser.

REDHAT:

UBUNTU:

GITHUB URL:

https://github.com/shrishtikapoor01/Ansible-OS-Redhat-Ubuntu-AWS.git

--

--

Shrishti Kapoor

Spread Knowledge because it’s all about Right Education..!!