Configure docker and launch container using ansible

#In Linux OS
pip3 install ansible
host_key_checking = false
- hosts: mywebtasks:
- command: "ls -l /dvd"
register: x
ignore_errors: yes
- file:
state: directory
path: "/dvd"
when: x.rc != 0
- mount:
src: "/dev/cdrom"
path: "/dvd"
state: mounted
fstype: "iso9660"
- yum_repository:
name: "docker"
description: "docker repo for package"
gpgcheck: no
- command: "rpm -q docker-ce"
register: y
ignore_errors: yes
- command: "yum install docker-ce --nobest -y"
when: y.rc != 0
- command: "systemctl status docker"
register: docker_status
ignore_errors: yes
- command: "systemctl start docker"
when: docker_status.rc != 0
- command: "systemctl enable docker"
when: docker_status.rc != 0
- pip:
name: "docker-py"
- docker_container:
name: "mycontainer"
state: started
image: httpd
restart: yes
- "1235:80"
- /mywebdata:/usr/local/apache2/htdocs/
register: c
- template:
dest: "/mywebdata"
src: "index.html"
- firewalld:
masquerade: yes
state: enabled
permanent: yes
immediate: yes
ansible-playbook docker.yml




enthusiastic for new technologies

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why I, Andre Thompson, Wish to become a computer scientist and student at Holberton School.

Singleton Design Pattern (Java Implementation)

Progressive Web Apps in B2B

ASP.NET Dependency Injection — Deep Dive

Leetcode — (2001.) Number of Pairs of Interchangeable Rectangles

How to Convert PDF to Word

Swiftapply — automatically efficient pandas apply operations

How to evaluate resume of a Software Engineer

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
Dhiraj Kumar

Dhiraj Kumar

enthusiastic for new technologies

More from Medium


CI pipeline template for Python in Gitlab

Install docker on CentOS 8 | Rocky Linux 8

Install docker on CentOS 8 | Rocky Linux 8

Docker Basic Commands — Part 02