forked from devgateway/dg-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.yml
More file actions
84 lines (74 loc) · 2.24 KB
/
deploy.yml
File metadata and controls
84 lines (74 loc) · 2.24 KB
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
---
- name: Deploy
hosts:
- "{{ project_title | regex_replace('[^\\w_]', '_') | lower }}_{{ tag }}"
vars:
product: "{{ project_title | regex_replace('[^\\w_]', '_') | lower }}"
systemd_service:
Unit.Description: "{{ project_title }}"
Unit.After: docker.socket docker.service
Unit.BindsTo: docker.socket docker.service
Install.WantedBy: multi-user.target
Service.Type: exec
Service.ExecStart: /usr/bin/docker-compose --no-ansi up
Service.WorkingDirectory: "/opt/devgateway/{{ product }}"
Service.Environment: "TAG={{ tag }} REPO={{ repo }}"
tasks:
- name: Install packages
ansible.builtin.package:
name:
- firewalld
- docker-compose
tags:
- provision
- name: Open firewall ports
ansible.posix.firewalld:
service: http
state: enabled
permanent: true
immediate: true
zone: public
tags:
- provision
- name: Configure Systemd unit
community.general.ini_file:
path: /etc/systemd/system/{{ product }}.service
create: true
no_extra_spaces: true
section: "{{ item.key.split('.')[0] }}"
option: "{{ item.key.split('.')[1] }}"
value: "{{ item.value }}"
loop: "{{ systemd_service | dict2items }}"
loop_control:
label: "{{ item.key }}"
notify:
- Reload Systemd
- name: Install Compose file
ansible.builtin.copy:
src: docker-compose.yml
dest: "{{ systemd_service['Service.WorkingDirectory'] }}/"
notify:
- Restart stack
- name: Update images
ansible.builtin.command:
chdir: "{{ systemd_service['Service.WorkingDirectory'] }}"
cmd: /usr/bin/docker-compose pull --quiet
environment:
TAG: "{{ tag }}"
REPO: "{{ repo }}"
notify:
- Restart stack
when: pull | default(false)
- name: Enable Compose service
ansible.builtin.service:
name: "{{ product }}"
enabled: true
state: started
handlers:
- name: Reload Systemd
ansible.builtin.systemd:
daemon_reload: true
- name: Restart stack
ansible.builtin.service:
name: "{{ product }}"
state: restarted