]> git.immae.eu Git - github/fretlink/ansible-postgresql-role.git/blob - test/main.yml
tests: running tests on all supported PG versions
[github/fretlink/ansible-postgresql-role.git] / test / main.yml
1 ---
2 - name: Bring up docker containers
3 hosts: localhost
4 vars: &common_vars
5 postgres_barman_directory: "test-postgres-{{ postgres_version }}"
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 }}"
17 image: "python:3.7-{{ debian_release }}"
18 - name: postgres_one
19 image: "python:3.7-{{ debian_release }}"
20 links:
21 - "{{ postgres_barman_server }}"
22 - name: postgres_two
23 image: "python:3.7-{{ debian_release }}"
24 links:
25 - "{{ postgres_barman_server }}"
26 - postgres_one
27 - name: postgres_three
28 image: "python:3.7-{{ debian_release }}"
29 links:
30 - "{{ postgres_barman_server }}"
31 - postgres_one
32 roles:
33 - role: provision_docker
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}}"
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:
54 - username: tester
55 password: tester
56 - username: barman
57 password: "secret_cocktail"
58 permissions: 'SUPERUSER'
59 - username: replicator
60 password: "secret_repli"
61 permissions: 'REPLICATION'
62 databases:
63 - dbname: test_database
64 owner: tester
65 extensions:
66 - description: PostGis
67 apt_deps:
68 - "postgresql-{{ postgres_version }}-postgis-3"
69 names:
70 - postgis
71 - postgis_topology
72 - btree_gist
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
94 restore_directory: "{{ postgres_barman_directory }}"
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
122 postgres_barman_password: "secret_cocktail"
123 backup_method: rsync
124 standby_hosts: "{{ groups['db-all'][1:] }}"
125 retention_policy: 'RECOVERY WINDOW OF 7 DAYS'
126 with_items:
127 - postgres_barman
128 tags: provision_docker
129
130 - name: Test installing Postgresql role
131 hosts: primary:secondary
132 connection: docker
133 vars:
134 postgres_listen_addresses: ["{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"]
135 pre_tasks: &pre_tasks
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
139
140 - debug: msg="Running on host {{inventory_hostname}} ({{ hostvars[inventory_hostname].ansible_default_ipv4.address }})"
141 roles:
142 - { role: ansible-postgresql-role, tags: ['postgres'] }
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
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
162 - name: Test running Postgresql role when database is started
163 connection: docker
164 hosts: primary:secondary
165 vars:
166 postgres_listen_addresses: ["{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"]
167 pre_tasks: *pre_tasks
168 roles:
169 - { role: ansible-postgresql-role, tags: ['postgres'] }