Ansible Playbook📃 which will Dynamically load Variable file named same as OS_Name

Buddhiprakash Jain
3 min readMar 28, 2021

Hello Everyone!!🖐

In this Blog I am going to create a Ansible Playbook which will Dynamically load Variable file named same as OS_Name.

🔰For Create Same Playbook you need to follow the steps that are given below:-

STEP 1:-

Create a Folder of any Name in my case folder name is “webserver”

Creating Folder

STEP 2:-

Create file of any name in webserver folder

Creating file

STEP 3:-

Create ansible host file from any location:-

Creating ansible host file

STEP 4:-

Configure your ansible configuration file that is /etc/ansible.cfg

Configuration file of Ansible

💥NOTE:- Give Location of your Ansible host file :-

STEP 5:-

Content in /etc/ansible/hosts file

Content in /etc/ansible/hosts file

STEP 6:-

Content in file os.yml

Content file in os.yml

STEP 7:-

Create two more in folder webserver

Creating RedHat.yml file
Creating Ubuntu.yml

💥NOTE :- Both the name of file are same those i given above

STEP 8:-

Content of file RedHat.yml

Content in file RedHat.yml

STEP 9:-

Content in file Ubuntu.yml

Content in file Ubuntu.yml

STEP 10:-

Use Redhat and Ubuntu OS

This is my Redhat OS that is running in my local VM

Redhat VM

This is my Ubuntu OS that is running on AWS Cloud

STEP 11:-

Run the ansible playbook(os.yml) by using command “ansible-playbook os.yml”

Playbook Run

STEP 12:-

Use Ubuntu Instance Public IP in browser

Webserver Configure successfully

This shows Webserver in Ubuntu OS is Ready!!✅

STEP 13:-

Use RedHat vm IP in browser

Webserver Configure Successfully!!

This shows Webserver in RedHat vm is Ready!!✅

If you liked the above blog, please share it.

DM me on LinkedIn in case of suggestions/feedback/queries:

❗LinkedIN Profile Link:-

ThankYou🙏

--

--