Using Ansible to Install Docker

Arya Dhorajiya
2 min readNov 27, 2020

🔰Write an Ansible PlayBook that does the following operations in the managed nodes:
🔹 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

This was the task provided to me by Vimal Sir, in order to get our basic concepts for ansible playbook, better and easy to use in future

So, I did the given task in the following Steps:-

Step 1:- Checking the hosts availability.

Using the command ansible all — list-hosts to check the available hosts.

Step 2:- Creating an Ansible Playbook with the given commands

I wrote an Ansible playbook to first create Docker repo, then installed Docker using the command, to ensure installation. Then I created Docker container of image httpd and connected the ports between the servers.

Step 3: Executing the Ansible Playbook

So, this was the output of executing the playbook. It was successfully executed, and to check the execution, we open the webpage exposed to the docker container.

Step 4:- Checking the Output

This successfully states that We created a Docker container just by using the commands given in the ansible playbook

This shows the power of the declarative language used by Ansible

:)

--

--