Integration Of Ansible With Docker

Ansible with Docker

Hello World! In this article, I am going to talk about an overview of Ansible and Docker. How we can use Ansible Scripts with Docker. The blog is about writing the Ansible Playbook that does the operations in the managed nodes. To create this application we are using or writing as a script of Ansible Playbooks and also configuring the Docker. The first thing we should know, What is Ansible?, What is Docker? , How we integrate Ansible with Docker ?

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

What is Ansible?

Ansible

Ansible is an open-source IT Configuration Management, Deployment & Orchestration tool. It aims to provide large productivity gains to a wide variety of automation challenges. This tool is very simple to use yet powerful enough to automate complex multi-tier IT application environments.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

What is Docker?

Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

How we can Integrate Ansible with Docker?

There are some following steps to perform the practical are as follows.

1. Configure yum for the docker

2. Installing docker software

3. Start the docker services

4. Installing python3.6 software

5. Installing a docker-py package

6. Pull the httpd for docker

7. Copy the file into the /var/www/html directory

8. Run the httpd server and exposed it to public

So Let’s Start:

Firstly we create a yml file to perform the ansible task

gedit dockerhttpd.yml

Then, we are going to give the host-name where we are going to set up all the things

- hosts: dockerhost

Step 1: Configure yum for the docker

- name: conf yum for the docker
yum_repository:
name: dockerrepo
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
description: yum for the docker
gpgcheck: no

The Output of Step1:

Output

Step 2: Installing docker software

- name: install docker software
command: "yum install docker-ce -y --nobest"

The Output of Step2:

Cmd for installing the Docker

Step 3: Start the docker service

- name: start docker service
service:
name: "docker"
state: started
enabled: yes

The Output of Step3:

Docker Services Started

Step 4: Installing python3.6 software

- name: install software python36
package:
name: "python36"
state: present

The Output of Step4:

Python Installed

Step 5: Installing docker-py package

- name: install docker python library
pip:
name: docker-py

The Output of Step5:

Docker Installed

Step6: Pull the httpd for docker

- name: pull httpd for docker
docker_image:
name: "httpd"
source: pull

The Output of Step6:

Httpd Server

Step7: Copy the file into the /var/www/html directory

- name: copy the file
copy:
src: "docker.html"
dest: "/var/www/html/"

The Output of Step7:

Finally Output

Thank you very much for reading my blog hope it will help you:

If you like my blog please like and hit a subscribe to my profile.

You can find me on LinkedIn:

Software Engineer || Mobile App Developer