This repository has been archived by the owner on Nov 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ponyconf.yml
280 lines (245 loc) · 9.09 KB
/
ponyconf.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
---
- hosts: ponyconfs
vars:
ponyconf_sites:
- domain: 'cfp-2023.pycon.fr'
authenticator: gandi
- domain: '2023.cfp.roscon.fr'
authenticator: nginx
ponyconf_user: ponyconf
ponyconf_home: "/home/{{ ponyconf_user }}"
ponyconf_secret: !vault |
$ANSIBLE_VAULT;1.1;AES256
32626263653065663534326530636136303864343934346538323232356133616263383432333566
3166653266366566626362623864343464323934623166640a663838303764316131373938663432
30623833376433383766636362306361363137383639643130306536623135353362326539343164
3633303531643964390a616464376137613634663334646230343365343938633462643737376637
30383361643563373130393737616430316363363836333632393565616332666336643766613937
30386264356266373033383436383462333038656133363530313161646632353366393631393036
363439633164376438376431373935643634
tasks:
- name: Install dependencies
apt:
state: present
name:
- gettext
- name: Ponyconf user
user:
name: "{{ ponyconf_user }}"
home: "{{ ponyconf_home }}"
system: true
- name: PonyConf nginx redirection
include_role: name=nginx
vars:
nginx_domain: "cfp.pycon.fr"
nginx_certificates: ["cfp.pycon.fr"]
nginx_conf: |
server
{
listen [::]:80; listen 80;
server_name cfp.pycon.fr;
access_log /var/log/nginx/cfp.pycon.fr-access.log;
error_log /var/log/nginx/cfp.pycon.fr-error.log;
return 301 https://cfp-2023.pycon.fr$request_uri;
}
server
{
listen [::]:443 ssl; listen 443 ssl;
server_name cfp.pycon.fr;
access_log /var/log/nginx/cfp.pycon.fr-access.log;
error_log /var/log/nginx/cfp.pycon.fr-error.log;
include snippets/letsencrypt-cfp.pycon.fr.conf;
return 301 https://cfp-2023.pycon.fr$request_uri;
}
- name: PonyConf nginx config
include_role: name=nginx
loop: "{{ ponyconf_sites }}"
vars:
certbot_authenticator: "{{ item.authenticator }}"
nginx_domain: "{{ item.domain }}"
nginx_certificates: ["{{ item.domain }}"]
nginx_conf: |
server
{
listen [::]:80; listen 80;
server_name {{ item.domain }};
access_log /var/log/nginx/{{ item.domain }}-access.log;
error_log /var/log/nginx/{{ item.domain }}-error.log;
return 301 https://{{ item.domain }}$request_uri;
}
server
{
listen [::]:443 ssl; listen 443 ssl;
server_name {{ item.domain }};
access_log /var/log/nginx/{{ item.domain }}-access.log;
error_log /var/log/nginx/{{ item.domain }}-error.log;
include snippets/letsencrypt-{{ item.domain }}.conf;
location /static/ {
alias {{ ponyconf_home }}/static/;
}
location / {
proxy_pass http://unix:{{ ponyconf_home }}/ponyconf.sock;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Protocol $scheme;
}
}
- name: Clone PonyConf
become: true
become_user: "{{ ponyconf_user }}"
git:
repo: https://git.afpy.org/AFPy/PonyConf
dest: "{{ ponyconf_home }}/src/"
notify: restart ponyconf
- name: Setup PonyConf venv
become: true
become_user: "{{ ponyconf_user }}"
pip:
requirements: "{{ ponyconf_home }}/src/requirements.txt"
virtualenv_command: /usr/bin/python3 -m venv
virtualenv: "{{ ponyconf_home }}/venv/"
- name: Install gunicorn
become: true
become_user: "{{ ponyconf_user }}"
pip:
name: gunicorn
virtualenv_command: /usr/bin/python3 -m venv
virtualenv: "{{ ponyconf_home }}/venv/"
- name: PonyConf config
copy:
dest: "{{ ponyconf_home }}/src/afpy_settings.py"
owner: "{{ ponyconf_user }}"
group: "{{ ponyconf_user }}"
mode: 0600
content: |
from ponyconf.settings import *
SECRET_KEY = "{{ ponyconf_secret }}"
ALLOWED_HOSTS = {{ ponyconf_sites | map(attribute='domain') | to_json }}
DEBUG = False
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[{server_time}] {message}",
"style": "{",
}
},
"handlers": {
"mail_admins": {
"class": "django.utils.log.AdminEmailHandler",
"level": "ERROR",
# But the emails are plain text by default - HTML is nicer
"include_html": True,
},
"console": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "django.server",
},
"django.server": {
"level": "INFO",
"class": "logging.StreamHandler",
"formatter": "django.server",
},
},
"loggers": {
"": {"handlers": ["console"], "level": "INFO"},
"django": {
"handlers": ["console", "mail_admins"],
"level": "INFO",
"propagate": True,
},
},
}
STATIC_ROOT = '{{ ponyconf_home }}/static'
STATIC_URL = '/static/'
MEDIA_ROOT = '{{ ponyconf_home }}/media'
MEDIA_URL = '/media/'
DEFAULT_FROM_EMAIL = 'noreply@afpy.org'
SERVER_EMAIL = 'ponyconf@afpy.org'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = '127.0.0.1'
EMAIL_SUBJECT_PREFIX = "[PonyConf] "
EMAIL_PORT = 25
ADMINS = (
('PonyConf Admins', 'julien@afpy.org'),
)
TIME_ZONE = 'Europe/Paris'
LANGUAGE_CODE = 'fr-FR'
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_X_FORWARDED_HOST = True
del SITE_ID
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'cache',
}
}
SELECT2_CACHE_BACKEND = 'default'
- name: Migrate db
command: "{{ ponyconf_home }}/venv/bin/python manage.py migrate"
args:
chdir: "{{ ponyconf_home }}/src"
environment:
DJANGO_SETTINGS_MODULE: afpy_settings
register: migrate_result
changed_when: '" Applying " in migrate_result.stdout'
run_once: true
become: true
become_user: "{{ ponyconf_user }}"
- name: Create sites
command: "{{ ponyconf_home }}/venv/bin/python manage.py addsite {{ item.domain|quote }}"
loop: "{{ ponyconf_sites }}"
register: create_site
changed_when: '"Created" in create_site.stdout'
args:
chdir: "{{ ponyconf_home }}/src"
environment:
DJANGO_SETTINGS_MODULE: afpy_settings
- name: Collectstatic
command: "{{ ponyconf_home }}/venv/bin/python manage.py collectstatic --noinput"
args:
chdir: "{{ ponyconf_home }}/src"
environment:
DJANGO_SETTINGS_MODULE: afpy_settings
register: collectstatic_result
changed_when: '"Copying " in collectstatic_result.stdout'
- name: Compile gettext
command: "{{ ponyconf_home }}/venv/bin/python manage.py compilemessages"
args:
chdir: "{{ ponyconf_home }}/src"
notify: restart ponyconf
- name: Create Cache Table
command: "{{ ponyconf_home }}/venv/bin/python manage.py createcachetable"
args:
chdir: "{{ ponyconf_home }}/src"
environment:
DJANGO_SETTINGS_MODULE: afpy_settings
- name: "PonyConf service"
notify: restart ponyconf
copy:
dest: /etc/systemd/system/ponyconf.service
content: |
[Unit]
Description=PonyConf
After=network.target
[Service]
Type=simple
Environment="DJANGO_SETTINGS_MODULE=afpy_settings"
ExecStart={{ ponyconf_home }}/venv/bin/gunicorn --pid {{ ponyconf_home }}/ponyconf.pid \
--bind unix:{{ ponyconf_home }}/ponyconf.sock -w 2 ponyconf.wsgi
User={{ ponyconf_user }}
Group={{ ponyconf_user }}
WorkingDirectory={{ ponyconf_home }}/src/
Restart=on-failure
[Install]
WantedBy=multi-user.target
- name: Start PonyConf
service: name=ponyconf enabled=yes state=started daemon_reload=yes
handlers:
- name: restart ponyconf
systemd:
daemon_reload: true
state: restarted
name: ponyconf