-
Notifications
You must be signed in to change notification settings - Fork 0
/
playbook.yml
124 lines (104 loc) · 3.98 KB
/
playbook.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
- hosts: all
become: true
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
with_items:
- 'curl'
- 'software-properties-common'
- 'python-pip'
- '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 xenial 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: create directories
file: path=/usr/{{ item }} state=directory
with_items:
- 'nginx'
- 'web1'
- 'web2'
- name: get nginx files
get_url: url={{ item }} dest=/usr/nginx
with_items:
- 'https://gist.githubusercontent.com/yishait/a95aca6d6a84c42e62227e633c5acbc1/raw/b17dd9257f844f5d97aa97d72c0597b742cd0dd0/Dockerfile'
- 'https://gist.githubusercontent.com/yishait/a95aca6d6a84c42e62227e633c5acbc1/raw/321a903978d49f02d7a2e737e7bf403233f8572d/default.conf'
- 'https://gist.githubusercontent.com/yishait/a95aca6d6a84c42e62227e633c5acbc1/raw/42d321138ce16233e9e0675f364c3c2da8fbc832/nginx.conf'
- name: get node 1 files
get_url: url={{ item }} dest=/usr/web1
with_items:
- 'https://gist.githubusercontent.com/yishait/ad351692ea7df6b2908f34a82cd0e538/raw/5fdfcaa2b46546b63d07c0580dd55a6e485eb793/Dockerfile'
- 'https://gist.githubusercontent.com/yishait/ad351692ea7df6b2908f34a82cd0e538/raw/20674480cfba980f13913443db22dc887db33108/index.html'
- name: get node 2 files
get_url: url={{ item }} dest=/usr/web2
with_items:
- 'https://gist.githubusercontent.com/yishait/ad351692ea7df6b2908f34a82cd0e538/raw/5fdfcaa2b46546b63d07c0580dd55a6e485eb793/Dockerfile'
- 'https://gist.githubusercontent.com/yishait/142ec1cc013322a2ddce191668a0f404/raw/b32aa0b8c551e5fe7b6e12871110b90e9354a06b/index.html'
- name: Create my_docker_network with custom IPAM config
docker_network:
name: my_docker_network
- name: build Nginx from dockerfile
docker_image:
name: nginx
path: /usr/nginx
state: present
- name: build node-1 from dockerfile
docker_image:
name: httpd1
path: /usr/web1
state: present
- name: build node-2 from dockerfile
docker_image:
name: httpd2
path: /usr/web2
state: present
##########################################################################
## start applications ##
##########################################################################
- name: start node 1 container
docker_container:
name: apache_httpd1
image: httpd1
state: started
networks:
- name: my_docker_network
- name: start node 2 container
docker_container:
name: apache_httpd2
image: httpd2
state: started
networks:
- name: my_docker_network
- name: start container with healthcheck
docker_container:
name: nginx-lb
image: nginx:latest
state: started
published_ports:
- 80:80
networks:
- name: my_docker_network
healthcheck:
test: ["CMD", "curl", "--fail", "http://nginx.host.com"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 30s
- name: Remove logs and reload nginx
command: docker exec nginx-lb rm -rf /var/log/nginx/*
- name: Remove logs and reload nginx
command: "docker exec nginx-lb service nginx reload"