]>
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 | |
120 | primary_barman_password: "secret_cocktail" | |
121 | backup_method: rsync | |
122 | ansible_group: db-all | |
123 | retention_policy: 'RECOVERY WINDOW OF 7 DAYS' | |
124 | with_items: | |
125 | - postgres_barman | |
126 | tags: provision_docker | |
127 | ||
128 | - name: Test installing Barman role | |
129 | hosts: barman | |
130 | connection: docker | |
131 | vars: {} | |
132 | pre_tasks: &pre_tasks | |
133 | - name: "Build hosts file" | |
134 | shell: 'echo "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }} {{inventory_hostname}}" >> /etc/hosts' | |
135 | when: hostvars[inventory_hostname].ansible_default_ipv4.address is defined | |
136 | ||
137 | - debug: msg="Running on host {{inventory_hostname}} ({{ hostvars[inventory_hostname].ansible_default_ipv4.address }})" | |
138 | roles: | |
139 | - { role: barman, tags: ['barman'] } | |
140 | ||
141 | - name: Test installing Postgresql role | |
142 | hosts: primary:secondary | |
143 | connection: docker | |
144 | vars: | |
145 | postgres_listen_addresses: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}" | |
146 | pre_tasks: *pre_tasks | |
147 | roles: | |
c4606fce | 148 | - { role: ansible-postgresql-role, tags: ['postgres'] } |
d0bc90e0 P |
149 | tasks: |
150 | - name: Start postgres cluster | |
151 | service: name=postgresql state=started | |
152 | ||
153 | - name: Test connection to Postgres instances. | |
154 | become: true | |
155 | become_user: postgres | |
156 | become_method: su | |
157 | command: psql --port=5432 --command='select NOW()' | |
158 | ||
159 | ||
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'] } |