Hello everyone,
In this blog, we will be Creating 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.
Let's get started:
First create inventory in the Controller node
Here I have created an inventory and added the IP of my target nodes.
Now check the connectivity between managed node and controller node by pinging
Now create an ansible configuration file
To create an ansible conf file, create a file with an extension cfg.
Now I have created Variable files for RedHat Os and Ubuntu Os
- For Ubuntu OS create a variable file named Ubuntu-20.yml
- For Redhat Os create a variable file named RedHat-8.yml
Now I have created an HTML page
I have used a variable in the code that will dynamically fetch the OS name and print it.
And I will upload this page to the root document of OS
Now create Playbook to configure Webserver in both OS
This playbook will dynamically find the OS and configure the Webserver in it.
Now run the Playbook
To run the playbook use the command ansible-playbook
Here you can see the playbook run successfully!!!
Now let's check in our Os is the webserver configured or not?
- In RedHat OS
Here you can see the webserver is configured successfully!!
- In Ubuntu OS
Here also Web server is configured successfully!!
Now lets check webserver is working or not
- copy Redhat OS IP and paste that IP in browser with HTML web page that we have uploaded
Here you can see it is working.
- Now let's check for Ubuntu.
So that how we can configure web servers in different OS using Dynamic Variable.
Thank you!!!
Top comments (0)