/
post-deploy.yml
120 lines (110 loc) · 4.39 KB
/
post-deploy.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
---
- name: Home automation post-deployment configration
hosts: localhost
connection: local
become: true
vars:
mqtt_password: password
nginx_confd_path: /opt/docker/nginx/conf.d
tasks:
- name: Creating mqtt account and password
community.docker.docker_container_exec:
container: mosquitto
command: mosquitto_passwd -b -c /config/mosquitto.passwd mqtt {{ mqtt_password }}
# If Nginx is installed, reverse proxy and redirects can be configured.
- name: Checking for Nginx installation
stat:
path: "{{ nginx_confd_path }}"
register: nginx_confd
# This following tasks only run if the Nginx conf.d directory exists.
- name: Creating ESPHome reverse proxy config
copy:
dest: /opt/docker/nginx/conf.d/esphome.conf
force: no
content: |
# ESPHome redirection and SSL off-loading.
server {
server_name esphome.{{ ansible_hostname }}.{{ ansible_domain }};
listen 80;
return 301 https://esphome.{{ ansible_hostname }}.{{ ansible_domain }};
}
server {
server_name esphome.{{ ansible_hostname }}.{{ ansible_domain }};
listen 443 ssl;
location / {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:6052;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ace {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:6052;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /logs {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:6052;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
when: nginx_confd.stat.exists
- name: Creating Home Assistant reverse proxy config
copy:
dest: /opt/docker/nginx/conf.d/homeassistant.conf
force: no
content: |
# Home Assistant redirection and SSL off-loading.
server {
server_name homeassistant.{{ ansible_hostname }}.{{ ansible_domain }};
return 301 http://homeassistant.{{ ansible_hostname }}.{{ ansible_domain }}:8123;
}
# Do not use "proxy_set_header X-Forwarded-For $remote_addr;" or Home Assistant
# will block the request.
server {
server_name homeassistant.{{ ansible_hostname }}.{{ ansible_domain }};
listen 443 ssl;
location / {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:8123;
}
location /api/websocket {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:8123;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
when: nginx_confd.stat.exists
- name: Creating NodeRED reverse proxy config
copy:
dest: /opt/docker/nginx/conf.d/nodered.conf
force: no
content: |
# NodeRED redirection and SSL off-loading with additional config for websockets.
server {
server_name nodered.{{ ansible_hostname }}.{{ ansible_domain }};
listen 80;
return 301 https://nodered.{{ ansible_hostname }}.{{ ansible_domain }};
}
server {
server_name nodered.{{ ansible_hostname }}.{{ ansible_domain }};
listen 443 ssl;
location / {
proxy_pass http://{{ ansible_hostname }}.{{ ansible_domain }}:1880;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
notify: Reloading Nginx config
when: nginx_confd.stat.exists
handlers:
- name: Reloading Nginx config
community.docker.docker_container_exec:
container: nginx
command: service nginx reload