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

Alternatives to the 45 minute Presentation

Adding shields to enemies

Flutter Getting Started: Tutorial 4 ListView

Using a pre-seeded PostgreSQL docker image for faster CI/CD

Rust: Enterprise Services Need Not Suck

High-speed nut counting based on Computer Vision |

The Most Essential Python Libraries for Data Science

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

How to create a Docker image using Docker File and push it on Docker Hub.

Creating a Lightweight Local Windows K8S & Docker Development Environment

How to configure Security Headers in Nginx

Apache Tomcat with Nginx Proxy on Ubuntu 20.04