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