Saranya. S
4 min readNov 29, 2020

--

ARTH — Task 10 👨🏻‍💻

Task Description📄

🔰Write an Ansible PlayBook that does the following operations in the managed nodes:

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the docker container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the web server

INTRODUCTION:ANSIBLE

Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.

Ansible’s main goals are simplicity and ease-of-use. It also has a strong focus on security and reliability, featuring a minimum of moving parts, usage of OpenSSH for transport.

ANSIBLE ARCHITECTURE:

  • It consists of mainly controller node and target or managed node
  1. control node: Any machine with Ansible installed. You can run Ansible commands and playbooks by invoking the ansible or ansible-playbook command from any control node. You can use any computer that has a Python installation as a control node - laptops, shared desktops, and servers can all run Ansible. However, you cannot use a Windows machine as a control node. You can have multiple control nodes.
  2. Target or managed node: The network devices (and/or servers) you manage with Ansible. Managed nodes are also sometimes called “hosts”. Ansible is not installed on managed nodes.

MAIN STEP FOR THE TASK : CONFIGURING ANSIBLE IN CONTROL NODE -

STEP:1:Download ANSIBLE

cmd: pip3 install ansible

STEP:2:To create inventory

#Inventory: A list of managed nodes. An inventory file is also sometimes called a “hostfile”. Your inventory can specify information like IP address for each managed node. An inventory can also organize managed nodes, creating and nesting groups for easier scaling.

1)static inventory file is a plain text file containing a list of managed hosts or remote nodes whose numbers and IP addresses remain fairly constant.(inventory created by ourselves).

2) a dynamic host file keeps changing as you add new hosts or decommission old ones.

STEP:2.1:create a file

cmd: vim <filename>.txt [eg.,vim ip.txt or vim /root/ip.txt]

STEP:2.2:write a file

<ip> ansible_user=<user name> ansible_ssh_pass=<password> ansible_connection=ssh

STEP:3:To create ansible configuration file

  1. create a directory = cmd: mkdir /etc/ansible
  2. create a file = cmd: vim /etc/ansible/ansible.cfg

3. write a file:

To check:

cmd: ansible all — list-hosts (shows ip of target nodes that are connected)

STEP:4:To connect the hosts

cmd: dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

then install sshpass,

cmd: yum install sshpass

To check: ansible all -m ping

MAIN STEP COMPLETED!!!!

NOW, create a playbook:

  1. create a directory: cmd: mkdir /<name> [eg., mkdir /ws]
  2. cd /ws ->create a file : vim <file name>.yml [eg., vim web.yml]

wrie a file:

[hint: ports: <hostport>:<container port>]

Now, play the playbook;

cmd: ansible-playbook <file name>

NOW,SUCCESSFULLY WE HAVE DONE THE FOLLOWING STEPS,

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the docker container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the web server

TO CHECK :Go to manage node

1)to check whether docker configured,started and enabled….

cmd: systemctl status docker

2)to check whether httpd server image launched….

cmd : docker images

3)to check whether docker container is running ……

cmd : docker ps -a

4)to check whether html code copied and exposed to public and webserver started……

--

--