diff options
author | Paul B <paul+gh@bonaud.fr> | 2019-05-03 14:27:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 14:27:18 +0200 |
commit | b9038ad7484a472f1e745906fb0d26530061b58d (patch) | |
tree | 4416f99a827f63e37ab98d94c66126d33ab323b0 | |
parent | c6719a82860c7855fb749f98734fe17c38c2fe78 (diff) | |
parent | 99504fed92577795e1ab0bf2ec0cd30a2435799f (diff) | |
download | ansible-postgresql-role-b9038ad7484a472f1e745906fb0d26530061b58d.tar.gz ansible-postgresql-role-b9038ad7484a472f1e745906fb0d26530061b58d.tar.zst ansible-postgresql-role-b9038ad7484a472f1e745906fb0d26530061b58d.zip |
Merge pull request #8 from chtitux/barman-url1.5.0
Allow to set options for barman connectivity
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | defaults/main.yml | 2 | ||||
-rw-r--r-- | tasks/postgres-standby-barman.yml | 12 | ||||
-rw-r--r-- | templates/postgresql.10.conf.j2 | 2 | ||||
-rwxr-xr-x | templates/standby-clone.sh.j2 | 7 |
5 files changed, 23 insertions, 7 deletions
@@ -78,6 +78,13 @@ postgres_replication_hosts: | |||
78 | 78 | ||
79 | # Ansible related Configuration | 79 | # Ansible related Configuration |
80 | postgres_become_method: su # Optional | 80 | postgres_become_method: su # Optional |
81 | |||
82 | # Barman connectivity | ||
83 | postgres_barman_server: barman.example.com # Required if at least one server has archive_enabled enabled | ||
84 | postgres_barman_rsync_enabled: False # Optional | ||
85 | postgres_barman_rsync_options: '' # Optional | ||
86 | postgres_barman_remote_user: barman # Optional | ||
87 | postgres_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: ~ |
8 | postgres_backup_enabled: false | 8 | postgres_backup_enabled: false |
9 | postgres_barman_rsync_enabled: false | 9 | postgres_barman_rsync_enabled: false |
10 | postgres_barman_remote_user: barman | ||
10 | 11 | ||
11 | postgres_become_method: su | 12 | postgres_become_method: su |
12 | #------------------------------------------------------------# | 13 | #------------------------------------------------------------# |
@@ -18,4 +19,3 @@ postgres_locale_system: C.UTF-8 | |||
18 | postgres_locale_formats: C.UTF-8 | 19 | postgres_locale_formats: C.UTF-8 |
19 | postgres_text_search_config: pg_catalog.english | 20 | postgres_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 %} |
230 | archive_mode = on | 230 | archive_mode = on |
231 | archive_command = 'rsync -a %p barman@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f' | 231 | archive_command = 'rsync -a %p {{ postgres_barman_remote_user }}@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f' |
232 | {% else %} | 232 | {% else %} |
233 | archive_mode = off | 233 | archive_mode = off |
234 | archive_command = '' | 234 | archive_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 | ||
30 | echo Get previous backup from backups server | 30 | echo Get previous backup from backups server |
31 | sudo -u postgres \ | 31 | sudo -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 | ||
39 | echo Restoring .conf and server certificate | 36 | echo Restoring .conf and server certificate |