Configuring docker container using Ansible

Configuring docker container using Ansible

Hi there! Today we are going to set up a docker container and then ssh inside to set up a webserver inside the container. I have already discussed docker and containers in previous articles.

ansible.png

Let's Start

Our setup is like this :

  • IP 192.168.43.195 acts as our docker host and the same IP we have put into our Ansible inventory

  • We also have Linux VM which will act as an Ansible controller.

Now we will write the YAML file for our setup. Our YAML file looks like this

Screenshot (1093).png

You can check it here

Ansible container does not have ssh enabled so we can either build ssh enabled image of our own or here I have used a script that will set up ssh inside my container.

Screenshot (1094).png

Now let's run our code.

VirtualBox_Ansible Controller Redhat_13_03_2021_10_51_29.png

VirtualBox_Ansible Controller Redhat_13_03_2021_10_51_45.png

Our playbook ran successfully so let's check if the container is successfully configured with the webserver.

VirtualBox_Ansible CLI 2_13_03_2021_10_49_47.png

Screenshot (1092).png

Everything is working fine. So in this way, we can use ansible to configure and setup custom services inside the docker container.

Thank You for the time and see you again next time ....!!

Did you find this article valuable?

Support Written Wisdom by becoming a sponsor. Any amount is appreciated!