ARTH — Task 10

VYSAKH M
3 min readMar 16, 2021

Task 10: 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

Step 1

CONFIGURING ANSIBLE IN CONTROL NODE

Download Ansible

cmd: pip3 install ansible

Step 2 Create Inventory

Create one inventory file and add ip of managed nodes

for that we need to create a file:-

write the file with respective ip and username and password

Step 3 Create ansible conf file and append the inventory file

  • create one dir:- mkdir /etc/ansible
  • create a conf file:- vim /etc/ansible/ansible.cfg
  • add inventory to conf file
  • To check :- ansible all — list-hosts

Step 4 To connect host:-

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

then install sshpass:- yum install sshpass

To check: ansible all -m ping

Initial Setup is completed

Now we have to write the playbook

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

and write the playbook :-

code finished play and playbook

cmd:- ansible-playbook <file name>

code finished play and playbook

cmd:- ansible-playbook <file name>

Check whether httpd server image has launched

cmd :-docker images

To check the webserver is running or not

Thank you!!!

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

--

--