Provisioning Docker Using Ansible.
Ansible is an automation tool primarily used in configuration management.
In this tech article, i will try to install docker software on manage node and run a container image.
Pre- Requisites:
- 2 RHEL 8 OS running on Virtual Box. One OS will act as controller Node and other OS as Manage node. you can have as many as you wish.
- Install Ansible on Controller Node.
- Install python software.
- Knowledge of ansible modules.
- pip command understanding to install python library.
After initial environment setup is completed. Now, we will proceed with creating the ansible playbook to install Docker software and run a container.
Let me jot down the steps that needs to be executed.
STEP 1: Configure yum repository in manage node.
STEP 2: Install docker software on manage node.
STEP 3: Docker service set up and start service.
STEP 4: Install Docker python library.
STEP 5: Download the docker image from docker repository.
STEP 6: Run the docker container.
Module references:
PLAYBOOK TO INSTALL DOCKER :
This simple playbook will configure yum repository, install docker and run a Apache web-server (httpd) in a container.
- hosts: docker
tasks:
- name: Configure yum Repository.
yum_repository:
name: DockerReporsitory
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
description: docker Repository set up
enabled: true
state: present
gpgcheck: no
- name: Docker Installation.
command: "yum install docker-ce -y --nobest"
- name: Start the docker service post installation.
service:
name: "docker"
state: "started"
- name: Install docker python library.
pip:
name: docker-py
- name: Get a docker image from docker repository.
docker_image:
name: "httpd"
source: pull
- name: The httpd image is downloaded. Now, run the container.
docker_container:
name: ApacheWebserver
image: "httpd"