Dynamic Ansible-Playbook

Dynamic Ansible-Playbook

Task- 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. (Note: No need to use when keyword here)

Usually we use when keyword in place of if-else in Ansible but here we cannot use when keyword here so we have to create an Ansible Playbook which will dynamically load the variable file named same as OS_name.

So we create seperate *.yml files with the OS names:-

ls ansible.jpg

redhat.yml:-

redhatyml file.jpg

ubuntu.yml:-

ubuntuyml file.jpg

Now we import these files in the main.yml

testyml file.jpg

Now we run this playbook:-

httpd jinja.jpg

Now as you can see Ansible-playbook ran successfully and our host is a redhat operating system so httpd must have installed in the computer.

So we check by command:-

rpm -q httpd

httpdinstalled.jpg

So as you can see httpd is successfully installed in our redhat operating system which means our task is successfully completed.