Ansible Playbook which will dynamically load the variable file.

Rohitbhatt
3 min readJan 2, 2021

This blog is about how we can Configure a 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.(without the use of when keyword).

For this we have to launch two different OS. here i use Amazon Linux 2 and Ubuntu-20.04.

🔹First we have to update the Ip addresses in Inventory file(#vim /root/ip.txt) of controller node on which we want to configure something.

🔹Ansible Configuration file

In this file have to update both , Inventory file location and also our key to login into AWS Instance(key should be present in controller node). The path of file is #vim /etc/ansible/ansible.cfg.

Now check the connectivity of Managed Nodes with Controller Node.

#ansible all -m ping all command is used to check the connectivity.

Now we see our Ansible Playbook

🔹Ansible playbook

Amazon-2.yml file
Ubuntu-20.04.yml file

🔹 Running Playbook

Now we are done with the Controller node configuration..!!

Lets check it manually on managed node.

🔹Managed node

Lets have a look of what we configured actually.

Ubuntu-20.04.

🔹checking on browser

So, we finally we Configure a Ansible Playbook which will dynamically load the variable file.

For Furthur Queries, Suggestion’s Feel Free to Connect with me On Linkedin.

www.linkedin.com/in/rohit-bhatt-97499b188.

Thank you!!!!!!!!!

--

--