aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorThéophile Helleboid <theophile.helleboid@captaintrain.com>2019-05-02 17:24:20 +0200
committerThéophile Helleboid <theophile.helleboid@captaintrain.com>2019-05-03 14:10:05 +0200
commit99504fed92577795e1ab0bf2ec0cd30a2435799f (patch)
tree4416f99a827f63e37ab98d94c66126d33ab323b0
parentc6719a82860c7855fb749f98734fe17c38c2fe78 (diff)
downloadansible-postgresql-role-99504fed92577795e1ab0bf2ec0cd30a2435799f.tar.gz
ansible-postgresql-role-99504fed92577795e1ab0bf2ec0cd30a2435799f.tar.zst
ansible-postgresql-role-99504fed92577795e1ab0bf2ec0cd30a2435799f.zip
Allow to set options for barman connectivity
- Allow to pass arbitrary options - Build the URL in a dedicated step - Allow to specify path prefix for barman files - Add documentation in [README.md](README.md)
-rw-r--r--README.md7
-rw-r--r--defaults/main.yml2
-rw-r--r--tasks/postgres-standby-barman.yml12
-rw-r--r--templates/postgresql.10.conf.j22
-rwxr-xr-xtemplates/standby-clone.sh.j27
5 files changed, 23 insertions, 7 deletions
diff --git a/README.md b/README.md
index 5482bc6..050fb65 100644
--- a/README.md
+++ b/README.md
@@ -78,6 +78,13 @@ postgres_replication_hosts:
78 78
79# Ansible related Configuration 79# Ansible related Configuration
80postgres_become_method: su # Optional 80postgres_become_method: su # Optional
81
82# Barman connectivity
83postgres_barman_server: barman.example.com # Required if at least one server has archive_enabled enabled
84postgres_barman_rsync_enabled: False # Optional
85postgres_barman_rsync_options: '' # Optional
86postgres_barman_remote_user: barman # Optional
87postgres_barman_path_prefix: '~' # Optional, required if using rsync
81``` 88```
82 89
83#### Testing 90#### Testing
diff --git a/defaults/main.yml b/defaults/main.yml
index 5876e94..587779c 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -7,6 +7,7 @@ postgres_clusters: []
7# postgres_pgbadger_server: ~ 7# postgres_pgbadger_server: ~
8postgres_backup_enabled: false 8postgres_backup_enabled: false
9postgres_barman_rsync_enabled: false 9postgres_barman_rsync_enabled: false
10postgres_barman_remote_user: barman
10 11
11postgres_become_method: su 12postgres_become_method: su
12#------------------------------------------------------------# 13#------------------------------------------------------------#
@@ -18,4 +19,3 @@ postgres_locale_system: C.UTF-8
18postgres_locale_formats: C.UTF-8 19postgres_locale_formats: C.UTF-8
19postgres_text_search_config: pg_catalog.english 20postgres_text_search_config: pg_catalog.english
20#------------------------------------------------------------# 21#------------------------------------------------------------#
21
diff --git a/tasks/postgres-standby-barman.yml b/tasks/postgres-standby-barman.yml
index 65e87a6..6a94b75 100644
--- a/tasks/postgres-standby-barman.yml
+++ b/tasks/postgres-standby-barman.yml
@@ -1,4 +1,16 @@
1--- 1---
2- name: Compute barman remote URL
3 set_fact:
4 barman_remote_url: "{{ scheme }}{{ user }}{{ server }}{{ delimiter }}{{ path }}"
5 rsync_options: "{{ postgres_barman_rsync_options | default('') }}{{ rsync_password_file }}"
6 vars:
7 scheme: "{{ postgres_barman_rsync_enabled | ternary('rsync://', '') }}"
8 user: "{{ postgres_barman_remote_user is defined | ternary(postgres_barman_remote_user + '@', '') }}"
9 server: "{{ postgres_barman_server }}"
10 delimiter: "{{ postgres_barman_rsync_enabled | ternary('', ':')}}"
11 path: "{{ postgres_barman_path_prefix | default('~') }}"
12 rsync_password_file: "{{ postgres_barman_rsync_enabled | ternary(' --password-file=/var/lib/postgresql/.rsync_pass ', '') }}"
13
2- name: Copy secondary script 14- name: Copy secondary script
3 template: src=standby-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755 15 template: src=standby-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755
4 16
diff --git a/templates/postgresql.10.conf.j2 b/templates/postgresql.10.conf.j2
index 588020f..b07b22b 100644
--- a/templates/postgresql.10.conf.j2
+++ b/templates/postgresql.10.conf.j2
@@ -228,7 +228,7 @@ wal_log_hints = on # also do full page writes of non-critical updates
228 228
229{% if postgres_archive_enabled %} 229{% if postgres_archive_enabled %}
230archive_mode = on 230archive_mode = on
231archive_command = 'rsync -a %p barman@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f' 231archive_command = 'rsync -a %p {{ postgres_barman_remote_user }}@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f'
232{% else %} 232{% else %}
233archive_mode = off 233archive_mode = off
234archive_command = '' 234archive_command = ''
diff --git a/templates/standby-clone.sh.j2 b/templates/standby-clone.sh.j2
index 16a6930..2db44b6 100755
--- a/templates/standby-clone.sh.j2
+++ b/templates/standby-clone.sh.j2
@@ -29,11 +29,8 @@ sudo -u postgres mkdir -p /var/lib/postgresql/{{ postgres_version }}/{{ postgres
29 29
30echo Get previous backup from backups server 30echo Get previous backup from backups server
31sudo -u postgres \ 31sudo -u postgres \
32 time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \ 32 time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete {{ rsync_options }} \
33{% if postgres_barman_rsync_enabled|default(false) -%} 33 {{ barman_remote_url }}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \
34 --password-file=/var/lib/postgresql/.rsync_pass \
35{%- endif %}
36 {% if postgres_barman_rsync_enabled|default(false) -%}rsync://{%- endif -%}barman@{{ postgres_barman_server }}{%- if postgres_barman_rsync_enabled|default(false) -%}/backups{%- else -%}:~{%- endif -%}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \
37 /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/ 34 /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/
38 35
39echo Restoring .conf and server certificate 36echo Restoring .conf and server certificate