Ansible PlayBook to install docker -community edition and launch a docker container with httpd configured and service started .

Prasantmahato
3 min readDec 16, 2020

In this practical I used 192.168.43.103 as Controller Node and 192.168.43.105 as Managed Node .

In Ansible Playbook :

playbook

tasks:

STEP 1

Configuring Yum with docker repo link ,So that later if we ask the “package” module to install docker-ce package .It would be installed smoothly . Here I am using “copy” module.

configuring yum

STEP 2

Now , Installing Docker Package with help of “package” module .

Installing Docker

STEP 3

Installing Python Interpretor ,So that later if Docker requires python module ,I can install it easily .Here I used “package” module , ‘register’ keyword to register to all the output in value ,and then I used “debug” module which helped me to show the output when we run the playbook .

Installing Python

STEP 4

Now to launch any docker container ,We need to install docker-py module. Here I used ‘command’ and ‘register’ keyword and “debug” module .

Installing docker-py

STEP 5

Starting the docker services .I used “service” module here.

Starting docker services

STEP 6

To launch any container ,We need to have a Docker-Image and this practical is all about to launch a Web server. So in hub.docker.com ,There is one image which is purely dedicated on httpd which I am using .Here I used “docker_image” module .

Pull httpd image

STEP 7

Creating a new folder in the Managed node ,So that I could link that folder as my httpd document root folder .Here I used “file” module .

Making a directory

STEP 8

Creating a new webpage in that Folder, So that later I can link that folder in the document root. Here I used “copy” module .

Inserting the web page .

STEP 9

Launching a Docker container using httpd image which I downloaded before .Here I used “docker_container” module .

Creating Docker Container .

After Running the Playbook :

ansible-playbook docker1.yml

After running the playbook

Now Finally, My webpage is deployed which is running on httpd container .

Thankyou

For any queries and suggestions dm me .

--

--

No responses yet