Ansible Playbook that will dynamically load the variable file.

Ansible Playbook that will dynamically load the variable file.

🔅 Objective : 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.

First we have to install ansible in our controller node through pip3 as is a python module and written in python language.

pip3 install ansible

Then we have to create our inventory file which contains information of all our managed node.

No alt text provided for this image

After that we have to configure ansible.cfg file. This file contains the location of our inventory file ip.txt .

No alt text provided for this image

To check the list of hosts :

ansible all --list-host

We have controller node with IP Address 192.168.43.67 and managed node with IP Address 192.168.43.137. Let's check the connectivity between two:

ansible all -m ping
No alt text provided for this image

There are two pre- required yml files before running the main playbook:-

  • RedHat.yml
  • Ubuntu.yml

These are the variable files for main playbook.

RedHat.yml

No alt text provided for this image

Ubuntu.yml

No alt text provided for this image


For creating a playbook first we have to know the steps so that we can easily convert those steps into YAML codes in playbook using ansible document.

Now let's create ansible playbook using YAML format:

Note : While creating playbook make sure you have proper indentation !!

No alt text provided for this image


For more detailed information we can increase the verbosity by adding -v .

Now let's run the playbook :

ansible-playbook -vv task3.yml
No alt text provided for this image
No alt text provided for this image

Playbook runs successfully !! Now let's check whether httpd container is running on the top of our managed node.

Now let's check our webpage by entering the IP Address with the file name on google :

192.168.43.137/index.html
No alt text provided for this image

This is our webpage !!

Thank You!!

Aakash O.

SWE-1 @FICO | Ex-Billdesk | Ex-DevOps Intern @SimplifyVMS | 1530 @Leetcode | Spring Boot | Data Structures | Algorithms | System Design | DevOps | ReactJs

4y

Inspiring.. 😊

To view or add a comment, sign in

More articles by Ananya Jain

Insights from the community

Others also viewed

Explore topics