forked from vistasunil/devopsIQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.yaml
49 lines (42 loc) · 1.6 KB
/
docker.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
---
- hosts: "{{hostname}}"
become: true
vars:
- create_containers: 5
- default_container_name: my_website
- default_container_image: vistasunil/devopsdemo:latest
- container_port: "8"
tasks:
- name: Install aptitude using apt
apt: name=aptitude state=latest update_cache=yes force_apt_get=yes
- name: Install required system packages
apt: name={{ item }} state=latest update_cache=yes
loop: [ 'apt-transport-https', 'ca-certificates', 'curl', 'software-properties-common', 'python3-pip', 'virtualenv', 'python3-setuptools']
- name: Add Docker GPG apt Key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker Repository
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu bionic stable
state: present
- name: Update apt and install docker-ce
apt: update_cache=yes name=docker-ce state=latest
- name: Install Docker Module for Python
pip:
name: docker
- name: Pull default Docker image
docker_image:
name: "{{ default_container_image }}"
source: pull
# Creates the number of containers defined by the variable create_containers, using values from vars file
- name: Create default containers
docker_container:
name: "{{ default_container_name }}{{ item }}"
image: "{{ default_container_image }}"
state: started
exposed:
- "{{ container_port }}{{ item }}"
ports:
- "{{ container_port }}{{ item }}:80"
with_sequence: count={{ create_containers }}