Ansible-Playbook → Dynamically loads variable file same as os_name!!

Venkateshsandupatla
2 min readApr 25, 2021

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

(Note: No need to use when keyword here.)

The playbook should dynamically load the variable file named the same as os_name-> so we launched two instances one is RedHat and other is ubuntu.

Update their ip’s in the inventory file of ansible.

Two variable files with the same as os_name:

AnsibleConfig file:

Give chmod 400 permission to the private key of instances

Playbook for configuring web server with the help of these variable files

Run the playbook:

Now let's check the final output:- From RedHat instance, the webpage should be “This os is Redhat” and from ubuntu — “This os is ubuntu”!

GitHub Link:-

--

--