aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/main.yml
diff options
context:
space:
mode:
authorPaul B <paul.bonaud@capitainetrain.com>2018-08-31 11:49:09 +0200
committerPaul B <paul.bonaud@capitainetrain.com>2018-08-31 12:00:24 +0200
commitd0bc90e08c29e881c388c6803ed9c49dff1f1776 (patch)
treee5f633a7461f3d339ef89758fc7bb3f1b91563d3 /test/main.yml
downloadansible-postgresql-role-1.0.0.tar.gz
ansible-postgresql-role-1.0.0.tar.zst
ansible-postgresql-role-1.0.0.zip
Initial commit open sourcing Postgresql Ansible role1.0.0
Diffstat (limited to 'test/main.yml')
-rw-r--r--test/main.yml154
1 files changed, 154 insertions, 0 deletions
diff --git a/test/main.yml b/test/main.yml
new file mode 100644
index 0000000..19ff526
--- /dev/null
+++ b/test/main.yml
@@ -0,0 +1,154 @@
1---
2- name: Bring up docker containers
3 hosts: localhost
4 vars: &common_vars
5 postgres_version: 10
6 postgres_barman_directory: 'test-postgres-10'
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:
52 - username: barman
53 password: "secret_cocktail"
54 permissions: 'SUPERUSER'
55 - username: replicator
56 password: "secret_repli"
57 permissions: 'REPLICATION'
58
59 with_items:
60 - postgres_one
61 tags: provision_docker
62
63 - name: Group secondaries
64 add_host:
65 hostname: "{{item}}"
66 groups: secondary
67 <<: *common_vars
68 postgres_clusters:
69 - version: "{{ postgres_version }}"
70 name: 'main'
71 port: 5432
72 fsync_enabled: True
73 checksums: False
74 archive_enabled: True
75 barman_directory: "{{ postgres_barman_directory }}"
76 primary:
77 host: postgres_one
78 port: 5432
79 restore_directory: "{{ postgres_barman_directory }}"
80 replication_user: "replicator"
81 replication_password: "secret_repli"
82
83 with_items:
84 - postgres_two
85 - postgres_three
86 tags: provision_docker
87
88 - name: Group db-all
89 add_host:
90 hostname: "{{item}}"
91 groups: db-all
92 with_items:
93 - postgres_one
94 - postgres_two
95 - postgres_three
96 tags: provision_docker
97
98 - name: Group barman
99 add_host:
100 hostname: "{{item}}"
101 groups: barman
102 <<: *common_vars
103 barman_databases:
104 - name: "{{ postgres_barman_directory }}"
105 description: 'Main database'
106 primary_host: postgres_one
107 primary_barman_password: "secret_cocktail"
108 backup_method: rsync
109 ansible_group: db-all
110 retention_policy: 'RECOVERY WINDOW OF 7 DAYS'
111 with_items:
112 - postgres_barman
113 tags: provision_docker
114
115- name: Test installing Barman role
116 hosts: barman
117 connection: docker
118 vars: {}
119 pre_tasks: &pre_tasks
120 - name: "Build hosts file"
121 shell: 'echo "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }} {{inventory_hostname}}" >> /etc/hosts'
122 when: hostvars[inventory_hostname].ansible_default_ipv4.address is defined
123
124 - debug: msg="Running on host {{inventory_hostname}} ({{ hostvars[inventory_hostname].ansible_default_ipv4.address }})"
125 roles:
126 - { role: barman, tags: ['barman'] }
127
128- name: Test installing Postgresql role
129 hosts: primary:secondary
130 connection: docker
131 vars:
132 postgres_listen_addresses: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"
133 pre_tasks: *pre_tasks
134 roles:
135 - { role: postgresql, tags: ['postgres'] }
136 tasks:
137 - name: Start postgres cluster
138 service: name=postgresql state=started
139
140 - name: Test connection to Postgres instances.
141 become: true
142 become_user: postgres
143 become_method: su
144 command: psql --port=5432 --command='select NOW()'
145
146
147- name: Test running Postgresql role when database is started
148 connection: docker
149 hosts: primary:secondary
150 vars:
151 postgres_listen_addresses: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"
152 pre_tasks: *pre_tasks
153 roles:
154 - { role: postgresql, tags: ['postgres'] }