-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
153 lines (136 loc) · 3.38 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
---
- name: "Manage weather application"
hosts: all
become: true
tasks:
- name: Install aptitude
tags:
- setup
ansible.builtin.apt:
name: aptitude
update_cache: true
- name: Install required system packages
tags:
- setup
ansible.builtin.apt:
pkg:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- git
update_cache: true
- name: Install Docker python module
tags:
- setup
ansible.builtin.pip:
name:
- docker
- docker-compose
- name: Symlink docker-compose to /usr/bin
tags:
- setup
ansible.builtin.file:
src: /usr/libexec/docker/cli-plugins/docker-compose
dest: /usr/bin/docker-compose
state: link
- name: Add Docker GPG apt Key
tags:
- setup
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add Docker Repository
tags:
- setup
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal stable
state: present
- name: Update apt and install docker-ce
tags:
- setup
ansible.builtin.apt:
name: docker-ce
update_cache: true
- name: Add the user 'web'
tags:
- setup
ansible.builtin.user:
name: web
comment: Web App
- name: Recursively remove old application directory
tags:
- setup
ansible.builtin.file:
path: /app
state: absent
# - name: Move any existing repository away
# tags:
# - setup
# ansible.builtin.command: "mv -f /app /app.bak"
# args:
# removes: /app
- name: Git checkout application repository
tags:
- setup
ansible.builtin.git:
repo: 'https://github.com/jirikivaari/example_weather'
dest: /app
version: master
- name: Set env variables
tags:
- setup
ansible.builtin.copy:
content: "APPID={{ APPID }}\nNODE_ENV=production\n"
dest: "/app/.env"
mode: '0644'
- name: Change ownership of application directory
tags:
- setup
ansible.builtin.file:
path: /app
owner: web
state: directory
recurse: true
- name: Tear down existing services
tags:
- start
community.docker.docker_compose:
project_src: /app
state: absent
- name: Start services with compose
tags:
- start
community.docker.docker_compose:
services:
- nginx
- frontend
- backend
project_src: /app
build: true
env_file: /app/.env
register: output
- name: "Print debug output"
tags:
- start
ansible.builtin.debug:
var: output
- name: Restart services
tags:
- restart
community.docker.docker_compose:
project_src: /app
build: false
restarted: true
register: output
- name: Stop all services
tags:
- stop
community.docker.docker_compose:
project_src: /app
build: false
stopped: true
register: output