Task 14.2 and 14.3

python3 --version
pip3 install ansible
vim /etc/ansible/ansible.cfg
vim docker.yml- hosts: localhost
vars_prompt:
- name: container
prompt: "Container Name"
private: no

tasks:
- name: Creating Docker Repository
yum_repository:
name: docker
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable
gpgcheck: no
description: Docker Repo

- name: install docker
command: "docker"
register: d_s
failed_when: false

- name: Installing Docker
command: yum install docker-ce -y --nobest
when: d_s.rc != 0
args:
warn: no

- name: Starting Docker
service:
name: docker
state: started

- name: Installing file for ansible and docker integration
pip:
name: docker-py
state: present

- name: Pull httpd image
docker_image:
name: httpd
source: pull

- name: copy webpage
copy:
src: index.html
dest: /var/www/html/index.html

- name: Start httpd Container
docker_container:
name : "{{ container }}"
image: httpd
state: started
volumes: "/var/www/html/:/usr/local/apache2/htdocs/"
published_ports:
- 7000:81
register: docker_info

- debug:
var: docker_info.container.NetworkSettings.IPAddress

- name: "Updating in inventory"
template:
src: "nodeips.txt"
dest: "/root/main.txt"
ansible-playbook --syntax-check docker.yml
ansible-playbook docker.yml
systemctl status docker
curl http://172.17.0.5/index.html

STEP 1:-

STEP 2:-

STEP 3:-

STEP 4:-

STEP 5:-

STEP 6:-

STEP 7:-

STEP 8:-

STEP 9:-

STEP 10:-

STEP 11:-

STEP 12:-

STEP 13:-

Thanks for Reading the article !!! 🙌🏻

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store