Invoke the files on the basis of the distribution of the type of OS in ansible

Hello Guys !!
In this article , I will gonna to show you how we can invoke the files on the basis of the type of the OS
So, basically what we are going to do is , we will gonna to configure a target node as a web server but the interesting thing is , the name of the software will be decided at the run time like for RedHat distribution the name of software would be httpd for Ubuntu the name of the software would be apache2
so, for performing the above task we have a setup.yml file

See, the variable {{ ansible_facts.distribution }} variable , it will gonna to find the distribution of the OS using ansible facts and thus include the corresponding file… The file contains the variable name web_server having the value as the name of the software corresponding to the distribution..
Like let suppose the target host is of RedHat distribution then the Redhat.yml file will gonna to be include and the variable web_server containing the value httpd(because for RedHat httpd server is used) gets included … By this way the file on the basis of the distribution will gonna to be include ..
Also, the conf_file.cfg file looks like

the variable name ansible_facts_all_ipv4_addresses[0] contains the IP address of the target node
Now , run the setup.yml file . If all the configuration are right then it looks like

So, since my target host(in my case it was controller node itself as I run the playbook on the localhost) is of RedHat distribution so the httpd software gets downloaded and thus the localhost gets configured as web sever.

Then , I put the http request to the target host (localhost in my case) and it looks like

Thanks For Reading …………..:)