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.)
- Here you can see I have created one workspace which contains four files :
- RedHat-8.yml: This file contains package name httpd for Redhat os with document root.
- Ubuntu-18.yml: This file contains package name apache2 for ubuntu os with document root.
- homepage.html: This file contains the webpage content.
- code.yml: This file contains the ansible-playbook code which helps me to dynamically load the variable file named same as OS_name and just by using the variable names. for which I have used the var files as ansible facts where I have written distribution minus with distribution major version. so if we configure the webserver on the top of RedHat and Ubuntu, if the system feels they are running on the top of Redhat, it uses RedHat-8.yml while for ubuntu, it uses Ubuntu-18.yml.
- Here you can see on my localhost web server httpd is not installed. so let's deploy the playbook.
- So here you can see the playbook is successfully deployed.
- Now here you can see the package httpd is successfully installed, the webpage is copied and the webserver service started.
- and that’s the content….!!!
THAT’S ALL ….