]>
Commit | Line | Data |
---|---|---|
d0bc90e0 P |
1 | --- |
2 | - name: Bring up docker containers | |
3 | hosts: localhost | |
4 | vars: &common_vars | |
0415357e | 5 | postgres_barman_directory: "test-postgres-{{ postgres_version }}" |
d0bc90e0 P |
6 | postgres_barman_server: postgres_barman |
7 | barman_rsync_password: "secret_rsync" | |
8 | barman_rsync_allowed_hosts: 172.17.0.0/24 | |
9 | postgres_allowed_hosts: | |
10 | - user: all | |
11 | range: 172.17.0.0/24 | |
12 | postgres_replication_hosts: | |
13 | - user: replicator | |
14 | range: 172.17.0.0/24 | |
15 | inventory: | |
16 | - name: "{{ postgres_barman_server }}" | |
0415357e | 17 | image: "python:3.7-{{ debian_release }}" |
d0bc90e0 | 18 | - name: postgres_one |
0415357e | 19 | image: "python:3.7-{{ debian_release }}" |
d0bc90e0 P |
20 | links: |
21 | - "{{ postgres_barman_server }}" | |
22 | - name: postgres_two | |
0415357e | 23 | image: "python:3.7-{{ debian_release }}" |
d0bc90e0 P |
24 | links: |
25 | - "{{ postgres_barman_server }}" | |
26 | - postgres_one | |
27 | - name: postgres_three | |
0415357e | 28 | image: "python:3.7-{{ debian_release }}" |
d0bc90e0 P |
29 | links: |
30 | - "{{ postgres_barman_server }}" | |
31 | - postgres_one | |
32 | roles: | |
33 | - role: provision_docker | |
0415357e P |
34 | vars: |
35 | provision_docker_inventory: "{{inventory}}" | |
36 | provision_docker_use_docker_connection: true | |
37 | ansible_connection: local | |
38 | ansible_python_interpreter: "{{ansible_playbook_python}}" | |
d0bc90e0 P |
39 | tasks: |
40 | - name: Group primary | |
41 | add_host: | |
42 | hostname: "{{item}}" | |
43 | groups: primary | |
44 | <<: *common_vars | |
45 | postgres_clusters: | |
46 | - version: "{{ postgres_version }}" | |
47 | name: 'main' | |
48 | port: 5432 | |
49 | fsync_enabled: True | |
50 | checksums: False | |
51 | archive_enabled: True | |
52 | barman_directory: "{{ postgres_barman_directory }}" | |
53 | users: | |
dd54b748 P |
54 | - username: tester |
55 | password: tester | |
d0bc90e0 P |
56 | - username: barman |
57 | password: "secret_cocktail" | |
58 | permissions: 'SUPERUSER' | |
59 | - username: replicator | |
60 | password: "secret_repli" | |
61 | permissions: 'REPLICATION' | |
dd54b748 P |
62 | databases: |
63 | - dbname: test_database | |
64 | owner: tester | |
65 | extensions: | |
66 | - description: PostGis | |
67 | apt_deps: | |
0415357e | 68 | - "postgresql-{{ postgres_version }}-postgis-3" |
dd54b748 P |
69 | names: |
70 | - postgis | |
71 | - postgis_topology | |
72 | - btree_gist | |
d0bc90e0 P |
73 | |
74 | with_items: | |
75 | - postgres_one | |
76 | tags: provision_docker | |
77 | ||
78 | - name: Group secondaries | |
79 | add_host: | |
80 | hostname: "{{item}}" | |
81 | groups: secondary | |
82 | <<: *common_vars | |
83 | postgres_clusters: | |
84 | - version: "{{ postgres_version }}" | |
85 | name: 'main' | |
86 | port: 5432 | |
87 | fsync_enabled: True | |
88 | checksums: False | |
89 | archive_enabled: True | |
90 | barman_directory: "{{ postgres_barman_directory }}" | |
91 | primary: | |
92 | host: postgres_one | |
93 | port: 5432 | |
587f87bb | 94 | restore_barman_directory: "{{ postgres_barman_directory }}" |
d0bc90e0 P |
95 | replication_user: "replicator" |
96 | replication_password: "secret_repli" | |
97 | ||
98 | with_items: | |
99 | - postgres_two | |
100 | - postgres_three | |
101 | tags: provision_docker | |
102 | ||
103 | - name: Group db-all | |
104 | add_host: | |
105 | hostname: "{{item}}" | |
106 | groups: db-all | |
107 | with_items: | |
108 | - postgres_one | |
109 | - postgres_two | |
110 | - postgres_three | |
111 | tags: provision_docker | |
112 | ||
113 | - name: Group barman | |
114 | add_host: | |
115 | hostname: "{{item}}" | |
116 | groups: barman | |
117 | <<: *common_vars | |
118 | barman_databases: | |
119 | - name: "{{ postgres_barman_directory }}" | |
120 | description: 'Main database' | |
121 | primary_host: postgres_one | |
6037b0f8 | 122 | postgres_barman_password: "secret_cocktail" |
d0bc90e0 | 123 | backup_method: rsync |
6037b0f8 | 124 | standby_hosts: "{{ groups['db-all'][1:] }}" |
d0bc90e0 P |
125 | retention_policy: 'RECOVERY WINDOW OF 7 DAYS' |
126 | with_items: | |
127 | - postgres_barman | |
128 | tags: provision_docker | |
129 | ||
6037b0f8 P |
130 | - name: Test installing Postgresql role |
131 | hosts: primary:secondary | |
d0bc90e0 | 132 | connection: docker |
6037b0f8 | 133 | vars: |
0415357e | 134 | postgres_listen_addresses: ["{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"] |
d0bc90e0 | 135 | pre_tasks: &pre_tasks |
0415357e P |
136 | - name: "Build hosts file" |
137 | shell: 'echo "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }} {{inventory_hostname}}" >> /etc/hosts' | |
138 | when: hostvars[inventory_hostname].ansible_default_ipv4.address is defined | |
d0bc90e0 | 139 | |
0415357e | 140 | - debug: msg="Running on host {{inventory_hostname}} ({{ hostvars[inventory_hostname].ansible_default_ipv4.address }})" |
d0bc90e0 | 141 | roles: |
c4606fce | 142 | - { role: ansible-postgresql-role, tags: ['postgres'] } |
d0bc90e0 P |
143 | tasks: |
144 | - name: Start postgres cluster | |
145 | service: name=postgresql state=started | |
146 | ||
147 | - name: Test connection to Postgres instances. | |
148 | become: true | |
149 | become_user: postgres | |
150 | become_method: su | |
151 | command: psql --port=5432 --command='select NOW()' | |
152 | ||
153 | ||
6037b0f8 P |
154 | - name: Test installing Barman role |
155 | hosts: barman | |
156 | connection: docker | |
157 | vars: {} | |
158 | pre_tasks: *pre_tasks | |
159 | roles: | |
160 | - { role: barman, tags: ['barman'] } | |
161 | ||
d0bc90e0 P |
162 | - name: Test running Postgresql role when database is started |
163 | connection: docker | |
164 | hosts: primary:secondary | |
165 | vars: | |
0415357e | 166 | postgres_listen_addresses: ["{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"] |
d0bc90e0 P |
167 | pre_tasks: *pre_tasks |
168 | roles: | |
c4606fce | 169 | - { role: ansible-postgresql-role, tags: ['postgres'] } |