Task-14.3

Task-14.3

 𝗧𝗮𝘀𝗸 𝗗𝗲𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻 :

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.

No alt text provided for this image

In This task we have to create a dynamic var files , with name of remote system which we will used in the playbook.

In this task I am going to used AWS instances 1. RedHat-8 , 2. Ubuntu-20 you can use your local system also. But the challenge is how ansible SSH them , for that we need to configure our host file and ansible.cfg inventory .

In host file we need to add AWS key , which have been used at the time of instance launching , and also we required the user name of OS. Give user name according to their distribution.

So Let’s start the practical :

1 . Launch the two instances on AWS :

No alt text provided for this image

2.Configure the host file :

No alt text provided for this image

Here we need to give the user name according to the distribution and also need same aws key pair which have been used at the time of OS launching. Give your key name in .pem format.

3.Configuring ansible.cfg file :

No alt text provided for this image

Here we need to configure inventory file to ssh the instances.

In a playbook, we may want to execute different tasks, or have different goals, depending on the value of a fact (data about the remote system), a variable, or the result of a previous task. We may want the value of some variables to depend on the value of other variables. Or we may want to create additional groups of hosts based on whether the hosts match other criteria. We can do all of these things with conditionals.

Ansible uses Jinja2 tests and filters in conditionals. Ansible supports all the standard tests and filters, and adds some unique ones as well.

Now I am going to create a var file according to the OS name of distribution.

  1. Create the variable file with the RedHat.yml name
No alt text provided for this image

2. Create the another variable file with the Ubuntu.yml name

No alt text provided for this image

Now create the playbook to configure the webserver

No alt text provided for this image

After that we have to write create the index.html file which we are going to copy to the root document

No alt text provided for this image

Now lets check the list of the hosts

No alt text provided for this image

Here you can see that , lists of remote nodes .

Now I am going to ping all of them . To check the connectivity between the controller node and target node.

No alt text provided for this image

Here you can see we are successfully able to ping with all the target node

Now run the playbook to configure the webserver.

No alt text provided for this image

Here we can see that , playbook run successfully without any error.

Now go to the web-browser and check weather the web pages are copied or not ?

No alt text provided for this image
No alt text provided for this image

Here you can see the webpages are copied successfully.

Thanks!!


To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics