Today we are going to integrate the two most popular DevOps tools. Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning. Automation is crucial these days, with IT environments that are too complex and often need to scale too quickly for system administrators and developers to keep up if they had to do everything manually. Automation simplifies complex tasks, not just making developers’ jobs more manageable but allowing them to focus attention on other tasks that add value to an organization. In other words, it frees up time and increases efficiency. And Ansible, as noted above, is rapidly rising to the top in the world of automation tools.
Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.
So We are going to create one playbook of ansible which performs following tasks on Ec2 instance( I am using RedHat 8).
🔅 Configure yum for Docker
🔅 Configure Docker
🔅 Start and enable Docker services
🔅 Pull the httpd server image from the Docker Hub
🔅 Run the httpd container and expose it to the public
🔅 Copy the html code in /var/www/html directory and start the web server.
*** Our first step is to configure yum for Docker because Docker does not directly support on RedHat version 8 ***
name: Docker #This unique id for repo
file: test #This file name followed by extension .repo
description: This yum repo configure by ansible
Here I am using yum_repository as module of ansible.
***Second step is to Install and configure the Docker***
— name: Starting the Docker service
— name: Installing pip3
— name: Installing Docker sdk
Here I am using package module of ansible for installing Docker.
***Pulling the Httpd Image from DockerHub***
name: Pulling the httpd image
***Running Docker container and exposed it to public and copy the source code also to Docker volumes***
- name: Creating the docker volume
— name: Copy Source code into volumes
— name: Creating httpd container
So In this way we can Integrate Docker with Ansible.
keep Learning follow me on LinkedIn for more such articles