Configure Docker and Httpd using Ansible-Playbook.

GANESH KUMAR
3 min readMar 21, 2021

Task:-

  1. Configure Docker.
  2. Start and enable Docker Services.
  3. Pull the httpd server image from Docker Hub.
  4. Run the docker container and expose it to the public.
  5. Copy the html code in /var/www/html directory and start the web server.

Required: Mainly two Redhat OS.

Implementation:-

First I check in my managed Node is docker already install or not by using rpm command.

As we can see docker is not installed in our managed node..

So we go to our controller node where Ansible is already installed and create a vim file where we write our playbook script as follows for given task as above-

First we set target ip in our controller node so Can get where to configure..

Then we check the connectivity of our controller node with managed node by this command-

ansible all — list-hosts

We also check connectivity between Controller Node and worker Node by ping command —

The script of playbook for the given task but before this we check that we don’t have any file related to Docker and no docker image is running.

As we can see that no file is here yet but after running ansible our configuration and code file will be come here.

So this is the final code that we have to run in a yaml file

Now we run this code with following command —

ansible-playbook webserver.yml

after running this command our process will start and start configure the file and folder and our server in target node.

After competed this process we will go into the target node and check whether our files are there or not.?

As we can see our index.html file is there as well our docker services is also installed and running also.

Then we check our image is pulling from Dockerhub.

As we can see out image is also download from Docker Hub and it is working running as well.

Now we just go on the browser and check out our webserver is running.

So finally our webserver is configure on Docker using Ansible.

Thanks…

--

--