Arth-Task-10(Configure Docker Using Ansible)
Description of Task…………
đź”°Write an Ansible PlayBook that does the following operations in the managed nodes:
step1:- Configure Docker.
step2:- Start and enable Docker services.
step3:- Pull the httpd server image from the Docker Hub.
step4:- Run the docker container and expose it to the public.
step5:- Copy the html code in /var/www/html directory and start the web server.
Follow the step and solve the task……………..
Step1:- Create Ansible playbook Configure Docker.
In this step we write script to configure or install docker software. In this step write script how to install docker software using ansible.
“- name: docker yum repositiry
yum_repository:
name: docker-repo
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
enabled: true
description: my docker repo
gpgcheck: no
— name: Install docker software
command: “yum install docker-ce -y — nobest” ”
Above code use to write script for installing docker software ,
step2:- Start and enable Docker services.
In this step write code to start docker service.
- name: start docker service
service:
name: “docker”
state: started
step3:- Pull the httpd server image from the Docker Hub.
In this step write code to pull the docker images on the docker hub and write script to install python software.
- name: install software python36
package:
name: python36
state: present
— name: install docker python librery
pip:
name: docker-py
— name: pull docker images
docker_image:
name: httpd
source: pull
step4:- Run the docker container and expose it to the public.
In this step we write code to expose the outside world to view the webpage.
docker_container:
name: web1
image: httpd
state: started
exposed_ports:
— “80”
ports:
— “1234:80”
volumes:
— /htmpPage:/usr/local/apache2/htdocs/
step5:- Copy the html code in /var/www/html directory and start the web server.
In this step copy the code,source to destination.
- name: Creating a directory to copy html code
file:
path: “/htmpPage”
state: directory
— name: Copy the code
copy:
src: “home.html”
dest: “/htmlPage”
— name: run container
Github Link to download code…..https://github.com/imneeteeshyadav98/Ansible-Task-1
Run the code…….
Summary:-
In this task we learn how to configure docker using ansible how to install python software and docker software and how to download docker images on the docker hub repository.
Thanks vimal daga sir give high level idea to configure lots og great software using ansible.