Configure docker and launch container using ansible

#In Linux OS
pip3 install ansible
[defaults]
inventory=<inventory_file_path>
host_key_checking = false
role_path=<role_path_name>
- 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"
baseurl:
"https://download.docker.com/linux/centos/7/x86_64/stable/"
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
ports:
- "1235:80"
volumes:
- /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

Docker

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