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

Aakash Choudhary
3 min readJan 21, 2022

Hello Everyone!!🖐

I am back with another blog, in this Blog, I am going to create an Ansible Playbook which will Dynamically load a Variable file named the 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”.

STEP 2:-

Create file of any name in webserver folder.

STEP 3:-

Create ansible host file from any location:-

STEP 4:-

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

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

STEP 5:-

Content in /etc/ansible/hosts file.

STEP 6:-

Content in file os.yml

STEP 7:-

Create two more in folder webserver.

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

STEP 8:-

Content of file RedHat.yml

STEP 9:-

Content in file Ubuntu.yml

STEP 10:-

Use Redhat and Ubuntu OS

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

STEP 11:-

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

STEP 12:-

Use Ubuntu Instance Public IP in browser

This shows Webserver in Ubuntu OS is Ready!!✅

STEP 13:-

Use RedHat vm IP in browser

I hope you like this blog, For next blog topic suggestions or queries you can DM me on LinkedIn. If you like this blog make sure you clap it.

Thank You

Signing off 🙌

--

--