Integrating Ansible with Docker.

Mohd Sabir
3 min readFeb 21, 2021

--

Task Description :-

  • Create a Ansible Playbook to configure the docker
  • Create a Ansible Playbook which will create docker Image and launch the container with this image & update the inventory dynamically
  • Create a Ansible playbook which will configure webserver inside the docker container

Let’s start doing our task :-

  • Create a Ansible Playbook to configure the docker-

Let’s write Ansible playbook to configure the docker

configuredocker.yml

this playbook configure the docker in your base system, Let’s run this playbook.

ansible-playbook configuredocker.yml
  • Create a Ansible Playbook which will create docker Image and launch the container with this image & update the inventory dynamically

Let’s write playbook

container.yml

Before run this playbook we have to create Dockerfile

Let’s create Dockerfile:-

mkdir /dw
vim /dw/Dockerfile
Dockerfile

When we create docker image using this Dockerfile then SSH will be enabled in this image and we can connect our container with SSH.

Now let’s run our playbook:-

ansible-playbook container.yml

Output of playbook

  • Everything is working fine let move to another step.
  • Create a Ansible playbook which will configure webserver inside the docker container:-
container.yml

This above playbook launch the webserver inside container.

Let’s run this playbook

ansible-playbook webserver.yml

Playbook runs successfully.

Let’s connect our webserver

http://docker-host-ip:port-no/webpage-name

it’s working fine.

Thanks for Reading

--

--

Mohd Sabir
Mohd Sabir

Written by Mohd Sabir

DevOps Enthusiastic || Kubernetes || GCP || Terraform || Jenkins || Scripting || Linux ,, Don’t hesitate to contact on : https://www.linkedin.com/in/mohdsabir

No responses yet