Ansible PlayBook to Configure Docker and Exposing the container to Launch a website
Ansible - It is a tool to automate manual tasks. We have to write the code in a file called Ansible Playbook.
We can 1 Control Node that controls all the Target/Host Nodes.
Ip of my Control Node - 192.168.1.7
Ip of my Target Node - 192.168.1.5
Tasks -
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
First, we will put the IP address of our target node in inventory file of control node and put the location of our inventory file in the .cfg file of ansible.
Now we, will start writing our YAML file or ansible-playbook. Ansible has multiple modules to do the tasks.
On the top we will write the
- hosts: all
This is the syntax of YAML.
Then below it,
tasks:
This tells that we have to perform following tasks.
- You must have configured Yum repo.
- Install Docker
- Start Docker
- Install Python2 and 36 as if needed
- Install requests module needed by python
- Install docker module of python
- Pull Httpd image from docker
- Start the docker container by exposing port
- Copy the Website files in the exposed directory to container.
- Stop the Firewall
Finally, the playbook will look like.
The docker.repo file that is used
Run this file as
ansible-playbook playbook.yml
Now, Lets see that in our target node whether these changes are done or not
Docker Service Running
Container started
Website visible
Thank You for reading.
I would like to thanks Vimal Daga Sir.
My Email — ayanchawlae@gmail.com
My LinkedIn — https://www.linkedin.com/in/ayanchawlae/
Comments
Post a Comment