~verterok/canonical-identity-provider/bionic-support

1.1.1 by Simon Davy
inital version
1
---
2
- hosts: localhost
3
4
  vars:
87.1.1 by Guillermo Gonzalez
make it work in xenial
5
    user: "ubunet"
1.1.1 by Simon Davy
inital version
6
    hostdir: /srv/{{ hostname }}
7
    basedir: /srv/{{ hostname }}/{{ deployment }}
8
    code_dir: "{{ basedir }}/code"
20.1.1 by Simon Davy
added preload action
9
    archive_dir: "{{ basedir }}/code/archives"
24.1.15 by Simon Davy
add support for wheels
10
    current_dir: "{{ code_dir }}/{{ build_label }}"
44.1.3 by Simon Davy
reset to env
11
    venv: "{{ current_dir }}/env"
24.1.15 by Simon Davy
add support for wheels
12
    python: "{{ venv }}/bin/python"
13
    wheel_dir: "{{ current_dir }}/branches/wheels"
87.1.3 by Guillermo Gonzalez
workaround recursive log_dir declaration
14
    logs_dir: "{{ basedir }}/logs"
15
    sso_log: "{{ logs_dir }}/sso.log"
20.1.5 by Simon Davy
new action style
16
    oops_dir: "{{ basedir }}/logs/www-oops"
11.2.3 by Simon Davy
add migration action, use src provided dependencies
17
    conf_dir: "{{ basedir }}/etc"
56.2.1 by Simon Davy
enable dev with charm
18
    run_dir: "{{ basedir }}/run"
56.2.4 by Simon Davy
add runner helper, and split deploy config for reuse in dev
19
    bin_dir: "{{ basedir }}/bin"
87.1.3 by Guillermo Gonzalez
workaround recursive log_dir declaration
20
    migrate_log_dir: "{{ logs_dir }}/schema-updates"
56.2.1 by Simon Davy
enable dev with charm
21
    db_readonly_path: "{{ run_dir }}"
3 by Simon Davy
restart on new config, explode metapackage, website relation
22
    port: 8080
24.1.3 by Simon Davy
add conn-check support
23
    conn_check_script: "{{ current_dir }}/scripts/settings-to-conncheck.py"
24.1.12 by Simon Davy
add in support for saml config
24
    google_saml_key_path: "{{ conf_dir }}/saml-google-key.pem"
25
    google_saml_cert_path: "{{ conf_dir }}/saml-google-cert.pem"
83.1.1 by Daniel Manrique
Support user_authorized_key.
26
    user_authorized_key_dir: "/etc/ssh/user-authorized-keys/"
27
    user_authorized_key_path: "{{ user_authorized_key_dir }}/{{ user }}"
56.2.4 by Simon Davy
add runner helper, and split deploy config for reuse in dev
28
    manage: django_project/manage.py
56.2.11 by Simon Davy
support setting django_settings_module and remove app-devel logic
29
    DJANGO_SETTINGS_MODULE: "{{ django_settings_module }}"
66.1.1 by Daniel Manrique
Add custom rsyslog rotation config
30
    syslog_keep_days: 90
1.1.1 by Simon Davy
inital version
31
56.3.5 by Simon Davy
add talisker support
32
  pre_tasks:
33
    - name: detect if talisker is available
34
      tags:
35
          - config-changed
36
          - wsgi-file-relation-changed
37
      stat: path={{ code_dir }}/current/env/bin/talisker
38
      register: talisker
40.1.4 by Simon Davy
use django role as include
39
1.1.1 by Simon Davy
inital version
40
  roles:
41
    - role: nrpe-external-master
42
      check_name: check_http
24.1.4 by Simon Davy
add hostname to nagios check
43
      check_params: "-I 127.0.0.1 -H {{ hostname }} -p {{ port }} -e ' 200 OK' -u '/'"
11.2.16 by Simon Davy
update nrpe role
44
      service_description: "Verify sso is responding."
24.1.11 by Simon Davy
fix warning message, plus use nagios context supplied by subordinate
45
      service_context: "{{ relations['nrpe-external-master'][0].nagios_host_context }}"
11.2.16 by Simon Davy
update nrpe role
46
      service_groups: "{{ nagios_servicegroups }}"
24.1.11 by Simon Davy
fix warning message, plus use nagios context supplied by subordinate
47
      when: relations['nrpe-external-master'] and 'nagios_host_context' in relations['nrpe-external-master'][0]
1.1.1 by Simon Davy
inital version
48
11.2.9 by Simon Davy
expose combine config
49
    - role: directories-and-permissions
87.1.1 by Guillermo Gonzalez
make it work in xenial
50
      user: "ubunet"
1.1.1 by Simon Davy
inital version
51
      readonly_dirs:
52
        - "{{ code_dir }}"
20.1.1 by Simon Davy
added preload action
53
        - "{{ archive_dir }}"
1.1.1 by Simon Davy
inital version
54
        - "{{ conf_dir }}"
56.2.4 by Simon Davy
add runner helper, and split deploy config for reuse in dev
55
        - "{{ bin_dir }}"
1.1.1 by Simon Davy
inital version
56
      writable_dirs:
87.1.3 by Guillermo Gonzalez
workaround recursive log_dir declaration
57
        - "{{ logs_dir }}"
56.2.1 by Simon Davy
enable dev with charm
58
        - "{{ run_dir }}"
1.1.1 by Simon Davy
inital version
59
        - "{{ oops_dir }}"
11.2.8 by Simon Davy
feedback from review
60
        - "{{ migrate_log_dir }}"
1.1.1 by Simon Davy
inital version
61
11.2.11 by Simon Davy
working payload role, and much smaller wsgi-app role
62
    - role: payload
63
      group: "{{ user }}"
64
      payload_dir: "{{ code_dir }}"
20.1.8 by Simon Davy
add support for swift credentials, and rename revision to build_label for consistancy with other charms
65
      payload_archive: "{{ build_label }}/canonical-identity-provider.tbz2"
11.2.11 by Simon Davy
working payload role, and much smaller wsgi-app role
66
      base_uri: "{{ asset_base_uri }}"
20.1.8 by Simon Davy
add support for swift credentials, and rename revision to build_label for consistancy with other charms
67
      # passed through automatically, but documenting
68
      # swift_auth_url: "{{ swift_auth_url }}"
69
      # swift_credentials: "{{ swift_credentials }}"
70
      when: build_label != ""
11.2.11 by Simon Davy
working payload role, and much smaller wsgi-app role
71
1.1.1 by Simon Davy
inital version
72
    - role: wsgi-app
24.1.15 by Simon Davy
add support for wheels
73
      current_symlink: "{{ build_label }}"
11.2.10 by Simon Davy
clean up wsgi-app role to not create dirs/users
74
      service_name: "{{ hostname }}"
3 by Simon Davy
restart on new config, explode metapackage, website relation
75
      listen_port: "{{ port }}"
87.1.3 by Guillermo Gonzalez
workaround recursive log_dir declaration
76
      log_dir: "{{ logs_dir }}"
1.1.1 by Simon Davy
inital version
77
      wsgi_user: "{{ user }}"
78
      wsgi_group: "{{ user }}"
79
      wsgi_application: django_project.wsgi
56.2.1 by Simon Davy
enable dev with charm
80
      env_extra: "DJANGO_SETTINGS_MODULE={{ DJANGO_SETTINGS_MODULE }}"
81
      # clean up any old config in the relation
82
      wsgi_extra: ""
83
      wsgi_extra_config: |
56.2.11 by Simon Davy
support setting django_settings_module and remove app-devel logic
84
            reload = {{ 'True' if deployment == 'devel' else 'False' }}
56.3.5 by Simon Davy
add talisker support
85
            statsd_prefix = '{{ statsd_prefix }}'
86
            {% if statsd_hostport %}statsd_host = '{{ statsd_hostport }}'{% endif %}
56.2.1 by Simon Davy
enable dev with charm
87
      python_path: "{{ conf_dir }}"
24.1.15 by Simon Davy
add support for wheels
88
      # hardcode to always run the current symlink
56.3.5 by Simon Davy
add talisker support
89
      gunicorn_path: "{{ code_dir }}/current/env/bin/{{ 'talisker' if talisker.stat.exists else 'gunicorn' }}"
20.1.8 by Simon Davy
add support for swift credentials, and rename revision to build_label for consistancy with other charms
90
      when: build_label != ""
11.2.3 by Simon Davy
add migration action, use src provided dependencies
91
1.1.1 by Simon Davy
inital version
92
93
  tasks:
94
24.1.15 by Simon Davy
add support for wheels
95
    - name: check we have a working payload
96
      tags: 
97
        - config-changed
98
        - memcached-relation-changed
99
        - conn-check-relation-changed
100
        - wsgi-file-relation-changed
33.1.10 by Simon Davy
add explicit control of build_label to run migrations on
101
        - preload
40.1.4 by Simon Davy
use django role as include
102
        - migrate
24.1.15 by Simon Davy
add support for wheels
103
      stat: path={{ current_dir }}
104
      register: payload
105
11.2.8 by Simon Davy
feedback from review
106
    - name: install required charm packages
11.2.3 by Simon Davy
add migration action, use src provided dependencies
107
      tags:
11.2.8 by Simon Davy
feedback from review
108
        - install
109
        - upgrade-charm
110
      apt: pkg={{ item }}
111
      with_items:
112
        - unzip
44.1.2 by Simon Davy
use virtualenv in tarball
113
        - python-pip
80.1.1 by Ricardo Kirkner
make sure libpq5 is present to let CI pass
114
        # workaround to fix CI basing off broken staging missing libpq
115
        - libpq5
44.1.2 by Simon Davy
use virtualenv in tarball
116
117
    - name: install virtualenv-tools
118
      tags: 
119
        - install
120
        - upgrade-charm
44.1.4 by Simon Davy
bundle virtualenv-tools in the charm
121
      pip:
77.1.1 by Guillermo Gonzalez
use pip2 for virtualenv-tools install
122
        executable: pip2
44.1.4 by Simon Davy
bundle virtualenv-tools in the charm
123
        chdir: "{{ charm_dir }}"
124
        name: lib/virtualenv-tools
46.1.1 by Simon Davy
replace --ignore-installed with --upgrade
125
        extra_args: "--upgrade --no-index"
1.1.1 by Simon Davy
inital version
126
33.1.7 by Simon Davy
configure local postfix for email sending
127
    - name: check postfix relayhost
128
      tags: config-changed
129
      shell: postconf relayhost
130
      when: email_hostport != ""
131
      register: relayhost
132
133
    - name: enable postfix forwarder
134
      tags: config-changed
135
      shell: postconf -e relayhost={{ email_hostport }} && service postfix restart
33.1.10 by Simon Davy
add explicit control of build_label to run migrations on
136
      when: email_hostport != "" and email_hostport not in relayhost.stdout
33.1.7 by Simon Davy
configure local postfix for email sending
137
1.1.1 by Simon Davy
inital version
138
    - name: readonly file
139
      tags: 
140
        - config-changed
141
      file: 
142
        path: "{{ db_readonly_path }}/db.readonly"
143
        owner: "{{ user }}"
144
        group: "{{ user }}"
145
        state: "{% if readonly %}touch{% else %}absent{% endif %}"
146
56.3.5 by Simon Davy
add talisker support
147
    # temporary task to handle migration to talisker logging
148
    - name: test for linked logfile
149
      tags:
150
          - config-changed
151
      stat: path={{ sso_log }}
152
      register: log_file
153
      when: talisker.stat.exists
154
155
    # temporary task to handle migration to talisker logging
156
    - name: mv old log file
157
      tags:
158
          - config-changed
159
      command: mv {{ sso_log }} {{ sso_log }}.bak
160
      when: talisker.stat.exists and not log_file.stat.islnk
161
162
    - name: link log file
163
      tags:
164
          - config-changed
165
      file:
87.1.3 by Guillermo Gonzalez
workaround recursive log_dir declaration
166
        path: "{{ logs_dir }}/sso.log"
56.3.5 by Simon Davy
add talisker support
167
        src: /var/log/upstart/gunicorn.log
168
        state: link
169
      # temporary when until migrated to talisker
170
      when: talisker.stat.exists
171
44.1.2 by Simon Davy
use virtualenv in tarball
172
    # the next 2 tasks should really only run when the payload has *changed*
11.2.8 by Simon Davy
feedback from review
173
    - name: Install required sso packages
174
      tags:
175
        - config-changed
33.1.10 by Simon Davy
add explicit control of build_label to run migrations on
176
        - preload
11.2.8 by Simon Davy
feedback from review
177
      shell: xargs apt-get install -y < {{ current_dir }}/dependencies.txt
33.1.10 by Simon Davy
add explicit control of build_label to run migrations on
178
      when: build_label != "" and payload.stat.exists
24.1.15 by Simon Davy
add support for wheels
179
44.1.2 by Simon Davy
use virtualenv in tarball
180
    - name: relocate venv
181
      tags:
182
        - config-changed
183
        - preload
184
      shell: virtualenv-tools --update-path=auto {{ venv }}
47.2.12 by Simon Davy
remove last of old payload support
185
      when: build_label != "" and payload.stat.exists 
46.1.2 by Simon Davy
make charm cope wth both thin and fat payloads
186
1.1.1 by Simon Davy
inital version
187
    - name: Write charm config
188
      tags:
189
        - config-changed
190
        - memcached-relation-changed
191
        - memcached-relation-departed
40.1.4 by Simon Davy
use django role as include
192
        - migrate
1.1.1 by Simon Davy
inital version
193
      template:
194
        src: "{{ charm_dir }}/templates/settings.py.j2"
24.1.13 by Simon Davy
verify config before restarting, and make installing devel deps an action
195
        dest: "{{ conf_dir }}/test_settings.py"
24.1.15 by Simon Davy
add support for wheels
196
      when: build_label != "" and payload.stat.exists
197
24.1.13 by Simon Davy
verify config before restarting, and make installing devel deps an action
198
    - name: verify settings (will fail if combined config does not parse)
199
      tags:
200
        - config-changed
201
        - memcached-relation-changed
202
        - memcached-relation-departed
40.1.4 by Simon Davy
use django role as include
203
        - migrate
56.2.1 by Simon Davy
enable dev with charm
204
      sudo: yes
205
      sudo_user: "{{ user }}"
56.2.4 by Simon Davy
add runner helper, and split deploy config for reuse in dev
206
      command: "{{ python }} {{ manage }} check --pythonpath={{ conf_dir }} --settings=test_settings"
24.1.13 by Simon Davy
verify config before restarting, and make installing devel deps an action
207
      args:
208
        chdir: "{{ current_dir }}"
24.1.15 by Simon Davy
add support for wheels
209
      when: build_label != "" and payload.stat.exists
24.1.13 by Simon Davy
verify config before restarting, and make installing devel deps an action
210
211
    - name: set config file
212
      tags:
213
        - config-changed
214
        - memcached-relation-changed
215
        - memcached-relation-departed
40.1.4 by Simon Davy
use django role as include
216
        - migrate
56.2.11 by Simon Davy
support setting django_settings_module and remove app-devel logic
217
      command: mv "{{ conf_dir }}/test_settings.py" "{{ conf_dir }}/settings.py"
24.1.15 by Simon Davy
add support for wheels
218
      when: build_label != "" and payload.stat.exists
3 by Simon Davy
restart on new config, explode metapackage, website relation
219
      notify: Restart wsgi
1.1.1 by Simon Davy
inital version
220
56.2.11 by Simon Davy
support setting django_settings_module and remove app-devel logic
221
    - name: clean up test settings
222
      tags:
223
        - config-changed
224
        - memcached-relation-changed
225
        - memcached-relation-departed
226
        - migrate
227
      command: rm -f {{ conf_dir }}/test_settings.*
228
      when: build_label != "" and payload.stat.exists
229
56.2.4 by Simon Davy
add runner helper, and split deploy config for reuse in dev
230
    - name: Write manage.py runner
231
      tags:
232
        - config-changed
233
      template:
234
        src: "{{ charm_dir }}/templates/manage.j2"
235
        dest: "{{ bin_dir }}/manage"
236
        mode: 0750
237
      when: build_label != "" and payload.stat.exists
238
60.2.1 by Daniel Manrique
Attempt to use the leader-elected event to write leadership variable. Failed because the hook is buggy/unreliable :(
239
    - name: register leadership data
240
      tags:
241
        - config-changed
242
        - leader-elected
60.2.2 by Daniel Manrique
Create actual hooks and put them in hooks.py so the event works. Also added leader-settings-changed for non-leader units. THIS NOW WORKS
243
        - leader-settings-changed
60.2.1 by Daniel Manrique
Attempt to use the leader-elected event to write leadership variable. Failed because the hook is buggy/unreliable :(
244
      command: is-leader
245
      register: is_leader
246
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
247
    - name: create maintenance crontabs
60.2.1 by Daniel Manrique
Attempt to use the leader-elected event to write leadership variable. Failed because the hook is buggy/unreliable :(
248
      tags:
249
        - config-changed
250
        - leader-elected
60.2.2 by Daniel Manrique
Create actual hooks and put them in hooks.py so the event works. Also added leader-settings-changed for non-leader units. THIS NOW WORKS
251
        - leader-settings-changed
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
252
      cron:
253
        name: "sso maintenance tasks - {{item.name}}"
68.1.1 by Daniel Manrique
maintenance crontab timing is adjustable per-item - made session cleanup hoourly
254
        special_time: '{{item.when}}'
60.2.1 by Daniel Manrique
Attempt to use the leader-elected event to write leadership variable. Failed because the hook is buggy/unreliable :(
255
        job: "IS_LEADER='{{ is_leader.stdout }}'; if [ $IS_LEADER = 'True' ]; then {{ bin_dir }}/manage {{ item.command }} 2>&1 | logger -t sso-maintenance; fi"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
256
        cron_file: sso-periodic-maintenance
60.1.7 by Daniel Manrique
Use {{ user }} instead of hardcoding it
257
        user: "{{ user }}"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
258
      with_items:
259
        - name: clean_old_authtokens
260
          command: "clean_old_authtokens"
68.1.1 by Daniel Manrique
maintenance crontab timing is adjustable per-item - made session cleanup hoourly
261
          when: "daily"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
262
        - name: cleanup --sessions
263
          command: "cleanup --sessions"
68.1.1 by Daniel Manrique
maintenance crontab timing is adjustable per-item - made session cleanup hoourly
264
          when: "hourly"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
265
        - name: cleanup --nonces
266
          command: "cleanup --nonces"
68.1.1 by Daniel Manrique
maintenance crontab timing is adjustable per-item - made session cleanup hoourly
267
          when: "daily"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
268
        - name: cleanup --testdata
269
          command: "cleanup --testdata"
68.1.1 by Daniel Manrique
maintenance crontab timing is adjustable per-item - made session cleanup hoourly
270
          when: "daily"
81.2.1 by Daniel Manrique
Run unverified/suspended account handling management commands daily
271
        - name: check_unverified_accounts_consistency
272
          command: "check_unverified_accounts_consistency"
273
          when: "daily"
274
        - name: suspend_unverified_accounts
275
          command: "suspend_unverified_accounts"
276
          when: "daily"
277
        - name: delete_suspended_accounts
278
          command: "delete_suspended_accounts"
279
          when: "daily"
60.1.4 by Daniel Manrique
Leverage the "manage.py runner" for shorter cron command lines
280
40.1.4 by Simon Davy
use django role as include
281
    - name: migration
282
      tags:
283
        - migrate
284
      include: roles/django/tasks/main.yaml
56.2.1 by Simon Davy
enable dev with charm
285
      sudo: yes
286
      sudo_user: "{{ user }}"
40.1.4 by Simon Davy
use django role as include
287
      vars:
288
        src_dir: "{{ current_dir }}"
289
        grant_user: "{{ db_user }}"
290
        migrate_env:
56.2.1 by Simon Davy
enable dev with charm
291
          DB_USER: "{{ migrate_user }}"
292
          DB_PASSWORD: "{{ migrate_password }}"
293
          SSO_LOGS_DIR: "{{ migrate_log_dir }}"
294
          PYTHONPATH: "{{ conf_dir }}"
295
          DJANGO_SETTINGS_MODULE: "{{ DJANGO_SETTINGS_MODULE }}"
40.1.4 by Simon Davy
use django role as include
296
      when: build_label != "" and payload.stat.exists
297
24.1.12 by Simon Davy
add in support for saml config
298
    - name: Write google SAML key from config
299
      tags: config-changed
300
      copy: 
301
        content: "{{ google_saml_key | b64decode }}"
302
        dest: "{{ google_saml_key_path }}"
303
        group: "{{ user }}"
304
        mode: 0440
305
      when: google_saml_key != ""
306
      notify: Restart wsgi
307
308
    - name: Write google SAML cert from config
309
      tags: config-changed
24.1.15 by Simon Davy
add support for wheels
310
      copy:
24.1.12 by Simon Davy
add in support for saml config
311
        content: "{{ google_saml_cert | b64decode }}"
312
        dest: "{{ google_saml_cert_path }}"
313
        group: "{{ user }}"
314
        mode: 0440
315
      when: google_saml_cert != ""
316
      notify: Restart wsgi
317
3 by Simon Davy
restart on new config, explode metapackage, website relation
318
    - name: website name
319
      tags:
320
        - website-relation-changed
321
      command: >
11.2.17 by Simon Davy
update to latest charm-helpers and shared roles
322
        relation-set -r {{ item.__relid__ }}
3 by Simon Davy
restart on new config, explode metapackage, website relation
323
        hostname={{ local_unit.split('/')[0] }}
324
        port={{ port }}
11.2.17 by Simon Davy
update to latest charm-helpers and shared roles
325
      with_items: relations.website
11.2.3 by Simon Davy
add migration action, use src provided dependencies
326
24.1.3 by Simon Davy
add conn-check support
327
    - name: write conn-check config
328
      tags:
329
        - config-changed
330
        - conn-check-relation-changed
24.1.11 by Simon Davy
fix warning message, plus use nagios context supplied by subordinate
331
      shell: >
332
          relation-set -r {{ item.__relid__ }} 
56.2.1 by Simon Davy
enable dev with charm
333
          config="$({{python }} {{ conn_check_script }} -m {{ DJANGO_SETTINGS_MODULE }} --print | grep -v WARNING)" 
24.1.11 by Simon Davy
fix warning message, plus use nagios context supplied by subordinate
334
          nagios_servicegroups={{ nagios_servicegroups }}
24.1.3 by Simon Davy
add conn-check support
335
      args:
336
        chdir: "{{ current_dir }}"
24.1.10 by Simon Davy
fix conn-check, secure proxy settings
337
      environment:
56.2.1 by Simon Davy
enable dev with charm
338
          PYTHONPATH: ".:lib:{{ conf_dir }}"
339
          DJANGO_SETTINGS_MODULE: "{{ DJANGO_SETTINGS_MODULE }}"
24.1.3 by Simon Davy
add conn-check support
340
      with_items: relations['conn-check']
24.1.15 by Simon Davy
add support for wheels
341
      when: build_label != "" and payload.stat.exists
66.1.1 by Daniel Manrique
Add custom rsyslog rotation config
342
343
    - name: Write rsyslog logrotate configuration
66.1.2 by Daniel Manrique
Add a tag so it actually runs
344
      tags:
345
        - config-changed
66.1.1 by Daniel Manrique
Add custom rsyslog rotation config
346
      template:
347
        src: "{{ charm_dir }}/templates/rsyslog.j2"
348
        dest: "/etc/logrotate.d/rsyslog"
349
        mode: 0644
83.1.1 by Daniel Manrique
Support user_authorized_key.
350
351
    - name: Create authorized key directory 
352
      tags: config-changed
353
      file: 
354
        path: "{{ user_authorized_key_dir }}"
355
        state: directory
356
        mode: 0755
357
        owner: root
358
        group: root
359
      when: user_authorized_key != ""
360
361
    - name: Write authorized SSH key from config
362
      tags: config-changed
363
      copy: 
364
        content: "{{ user_authorized_key }}"
365
        dest: "{{ user_authorized_key_path }}"
366
        mode: 0444
367
      when: user_authorized_key != ""