Dynamic Configuration of Target nodes using variable files named same as OS using Ansible

Himanshi Kabra
2 min readMar 28, 2021

๐—ง๐—ฎ๐˜€๐—ธ ๐——๐—ฒ๐˜€๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜๐—ถ๐—ผ๐—ป :Create 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.

Here, weโ€™ll be using two target nodes. First one will be Redhat linux and second one will be Ubuntu.

We will set up the ansible over AWS using EC2 instance

Letโ€™s jump into the task

Step 1:

Launch the two instances on AWS :

Step 2:

Configure the host file :

Step 3:

Configuring ansible.cfg file :

Letโ€™s create the yml files for ansible

Step 1:

Create the variable file: RedHat.yml

Step 2:

Create the another variable file: Ubuntu.yml

Step 3:

Now create the playbook to configure the webserver

Finally, configure the index.html file

Now, lets run the playbook:

First letโ€™s check the hosts

We ping to the hosts inorder to check the connectivity between the controller node and target node.

Now run the playbook to configure the webserver

We have successfully completed the task. We can verify it by opening the webpages using the respective IP addresses of the systems.

--

--