|
8 | 8 | group: "plpsql"
|
9 | 9 | comment: "plpsql for Postgres"
|
10 | 10 | state: present
|
11 |
| - |
12 |
| -- name: get the user ids |
13 |
| - shell: > |
14 |
| - egrep "^plpsql:" /etc/passwd | awk -F: '{ print $3":"$4 }' |
15 |
| - changed_when: false |
16 |
| - register: user_group_id |
| 11 | + register: plpsql_user |
17 | 12 |
|
18 | 13 | - name: pipeline postgres PGDATA directory
|
19 | 14 | file: dest=/srv/pl-psql state=directory owner=plpsql group=plpsql mode=0700
|
|
22 | 17 | template: src=pg_hba.conf dest=/srv/pl-psql/pg_hba.conf owner=plpsql group=plpsql mode=0444
|
23 | 18 | notify: reload pl-psql
|
24 | 19 |
|
25 |
| -# Warning: hkgmetadb.infra.ooni.io is hardcoded here to identify the active and standby DBs |
26 |
| -# TODO: use a flag in inventory instead |
27 |
| - |
28 |
| -# active host |
29 |
| - |
30 | 20 | - name: place config in PGDATA for active DB
|
31 | 21 | template: src=postgresql.active.conf dest=/srv/pl-psql/postgresql.conf owner=plpsql group=plpsql mode=0444
|
32 | 22 | notify: reload pl-psql
|
33 |
| - when: inventory_hostname == 'hkgmetadb.infra.ooni.io' |
| 23 | + when: "'db_active' in group_names" |
34 | 24 |
|
35 | 25 | - name: drop recovery.conf from PGDATA on active DB
|
36 | 26 | file: name=/srv/pl-psql/recovery.conf state=absent
|
37 | 27 | notify: reload pl-psql
|
38 |
| - when: inventory_hostname == 'hkgmetadb.infra.ooni.io' |
39 |
| - |
40 |
| -# standby hosts |
| 28 | + when: "'db_active' in group_names" |
41 | 29 |
|
42 | 30 | - name: place config in PGDATA for standby DB
|
43 | 31 | template: src=postgresql.standby.conf dest=/srv/pl-psql/postgresql.conf owner=plpsql group=plpsql mode=0444
|
44 | 32 | notify: reload pl-psql
|
45 |
| - when: inventory_hostname != 'hkgmetadb.infra.ooni.io' |
| 33 | + when: "'db_standby' in group_names" |
46 | 34 |
|
47 | 35 | - name: place recovery.conf to PGDATA on standby DB
|
48 | 36 | template: src=recovery.conf dest=/srv/pl-psql/recovery.conf owner=plpsql group=plpsql mode=0444
|
49 | 37 | notify: reload pl-psql
|
50 |
| - when: inventory_hostname != 'hkgmetadb.infra.ooni.io' |
| 38 | + when: "'db_standby' in group_names" |
| 39 | + |
| 40 | +# TODO fix this with the apt module once we update to the latest debian |
| 41 | +# apt: |
| 42 | +# name: openvpn |
| 43 | +# install_recommends: no |
| 44 | + |
| 45 | +- name: install openvpn |
| 46 | + command: apt-get install --no-install-recommends -y openvpn |
| 47 | + tags: dbvpn |
| 48 | + |
| 49 | +- name: openvpn create conf on standby node |
| 50 | + template: src=openvpn.standby.conf dest=/etc/openvpn/oonidbvpn.conf |
| 51 | + notify: systemctl daemon-reload |
| 52 | + when: "'db_standby' in group_names" |
| 53 | + tags: dbvpn |
| 54 | + |
| 55 | +- name: openvpn create conf on active node |
| 56 | + template: src=openvpn.active.conf dest=/etc/openvpn/oonidbvpn.conf |
| 57 | + notify: systemctl daemon-reload |
| 58 | + when: "'db_active' in group_names" |
| 59 | + tags: dbvpn |
| 60 | + |
| 61 | +- name: openvpn create shared secret on active node |
| 62 | + command: openvpn --genkey --secret /etc/openvpn/oonipgvpn.key |
| 63 | + args: |
| 64 | + creates: /etc/openvpn/oonipgvpn.key |
| 65 | + notify: restart openvpn |
| 66 | + when: "'db_active' in group_names" |
| 67 | + tags: dbvpn |
| 68 | + |
| 69 | +- name: openvpn copy shared secret from active node |
| 70 | + slurp: |
| 71 | + src: /etc/openvpn/oonipgvpn.key |
| 72 | + register: pgvpn_secret |
| 73 | + when: "'db_active' in group_names" |
| 74 | + tags: dbvpn |
| 75 | + |
| 76 | +- name: openvpn copy shared secret to standby node |
| 77 | + copy: |
| 78 | + content: "{{ pgvpn_secret }}" |
| 79 | + dest: /etc/openvpn/oonipgvpn.key |
| 80 | + notify: restart openvpn |
| 81 | + when: "'db_standby' in group_names" |
| 82 | + tags: dbvpn |
51 | 83 |
|
52 | 84 | # if `initdb` fails read `Arbitrary --user Notes` at https://hub.docker.com/_/postgres/
|
53 | 85 | - name: docker run pipeline postgres
|
|
86 | 118 | PUSHGATEWAY_CERT: "/srv/pl-psql_ssl/pusher/{{ inventory_hostname }}.cert"
|
87 | 119 | PUSHGATEWAY_KEY: "/srv/pl-psql_ssl/pusher/{{ inventory_hostname }}.key"
|
88 | 120 | stop_signal: SIGINT # Fast shutdown. Default SIGTERM waits for all the sessions to terminate.
|
89 |
| - user: "{{ user_group_id.stdout }}" |
| 121 | + user: "{{ plpsql_user.uid }}:{{ plpsql_user.group }}" |
90 | 122 | stop_timeout: 60 # default is 10
|
91 | 123 | restart_policy: unless-stopped
|
92 | 124 | ...
|
0 commit comments