How to configure a Web Server on Docker using Ansible?
You should have pre-configured controller and managed node of ansible.
So, let’s get started…
Step 1:- First, we have to configure yum for installing the docker. The code for the same is as follows:-
- hosts: all
description: "Docker yum repo"
name: "Docker Repo"
Step 2:- Now, download the docker software using the following code:-
Step 3:- Before starting the docker service, we need to install a python package named docker-py in the target node as ansible is dependent on python. By installing docker-py, the system will understand that docker is using the correct and same version of python as used by the system. The code for the same is as follows:-
Step 4:- Next, we have to start and enable the docker services. The code for the same is as follows:-
Step 5:- Now, we have to create a directory in the managed node to attach container and copy web page to it. Use the following code for the same:-
path: "/Webserver"- copy:
Step 6:- Next, we have to pull the HTTPD image from the Docker hub, launch docker container, run HTTPD server in it and make it publicly accessible. The code for the same is as follows:-’
source: pull- docker_container:
Step 7:- Now, run the playbook by using the following command :-
Finally, you can access the web page.
Thank you :)