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:-
redhat.yml:-
ubuntu.yml:-
Now we import these files in the main.yml
Now we run this playbook:-
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
So as you can see httpd is successfully installed in our redhat operating system which means our task is successfully completed.