ARTH Task 14

Akhilesh Jain
4 min readMar 29, 2021

--

So, this blog is related to the Task given to us in my ARTH Training. So this blog consists of 3 parts:

1st Part: Arth Task 14.1

Statement: Creating a network Topology Setup in such a way so that System A can ping to two Systems System B and System C but both these systems should not be pinging each other without using any security rule e.g firewall etc.

2nd Part: Arth Task14.2

Statement: Creating an Ansible playbook that will retrieve New Container IP and update the inventory, So that further Configuration of Webserver could be done inside that Container.

I have created a Video for this Task, which is added at the end of this section. Following is the structure of the Task Directory:

  • ansible.cfg — This file consists of the configuration, ansible will use while running playbook.
[defaults]
inventory = ./inventory.txt
host_key_checking = false
ask_pass = false
[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false
  • inventory.txt — This file consists of the hosts, on which playbook will run.
[web2]
ansiblemn2 ansible_ssh_user=root ansible_ssh_pass=1 ansible_connection=ssh
[docker]
  • task10-docker.yml — This file is the sample of my Arth Task10, as this Task 14 is the extended task of our Task 10.

So, in this Task, I have created 2 playbooks:

  • docker.yml — This file will create docker repo, install it and start it. After then it will create docker container with some ports Exposed, and then main thing is, it will dynamically update my inventory file, so that the next playbook we run can be run without adding the hosts automatically.
  • web-docker.yml — This file is used to install httpd package, and start service and then create a page in that server.

Firstly, We run the docker.yml playbook:

ansible-playbook docker.yml

After the Playbook runs Successfully, we can see that inventory gets updated:

[web2]
ansiblemn2 ansible_ssh_user=root ansible_ssh_pass=1 ansible_connection=ssh
[docker]
172.17.0.2 ansible_ssh_user=root ansible_ssh_pass=root

Now, we can run other playbook ‘web-docker.yml’ playbook:

ansible-playbook web-docker.yml

So, when this playbook runs successfully, we will see that webserver is running, and using curl commands we can get the output of the page.

→ This is the Video, I have created to better show the procedure and outputs:

3rd Part: Arth Task 14.3

Statement: 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.
(Note: No need to use when keyword)

I have created a Video for this Task, which is added at the end of this section. Following is the structure of the Task Directory:

  • ansible.cfg — This file consists of the configuration, ansible will use while running playbook.
[defaults]
inventory = ./inventory.txt
host_key_checking = false
ask_pass = false
[privilege_escalation]
become = true
become_method = sudo
become_user = root
become_ask_pass = false
  • inventory.txt — This file consists of the hosts, on which playbook will run.
[web2]
ansiblemn2 ansible_ssh_user=root ansible_ssh_pass=1 ansible_connection=ssh
  • RedHatOS.yml — This file is a variable file, which contains variables of Packages and Services of Redhat OS.
  • UbuntuOS.yml — This file is a variable file, which contains variables of Packages and Services of Ubuntu OS.
  • playbook.yml — This file is the playbook which will fetch the OS Distribution Name, and according to that, packages of the particular OS will be installed and their respective services will be started.

Note: OS Distribution Name(OS Name) will be fetched of the respective hosts on which Playbook will run.

To run the playbook:

ansible-playbook playbook.yml

After the runs Successfully, we will see the Webserver is started.

→ This is the Video, I have created to better show the procedure and outputs:

I have learned of these tools, under the mentorship of Mr. Vimal Daga Sir under Arth Training.

I hope this article is Informative and Explanatory. Hope you like it !!!

Please give some claps, if you liked this article !!!

For any suggestions or if any reader find any flaw in this article, please email me to “akhileshjain9221@gmail.com”

Thank You Readers, for viewing this !!!

--

--

Akhilesh Jain

I am a student and persuing under graduation in computer science and engineering.