What is Docker?
Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels
So, What are we going to deploy here?
We are going to write a playbook that’s gonna perform the following tasks:-
🔅 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
Firstly check if ansible is installed or not
Next create a ansible.cfg file with the following content:
Create the inventory containing the IP of the managed node in the same directory as of ansible.cfg file.
<IP of managed node> ansible_ssh_user=root ansible_ssh_pass=password
Once Ansible is successfully configured, we can go on with creating the ansible playbook: —
- name: Setup docker on managed node
- name: Configure docker repo
description: Yum repo for docker
gpgcheck: no - name: Install docker
command: yum install docker-ce --nobest -y - name: Install python3
state: present - name: Install docker SDK
name: docker-py - name: Start and enable docker service
enabled: yes - name: Pull docker image
source: pull - name: Create workspace directory
state: directory - name: Copy webpage content
content: "<h1>This webpage is configured inside a docker container deployed using Ansible.</h1>"
dest: /root/Task10/web/index.html - name: Allow port through firewall
state: enabled - name: Run a docker container
Let’s deploy the playbook now —
So, let’s check whether the webserver has been containerized or not —
http://<IP of managed node>:8081
Deployment successful !!