]> git.immae.eu Git - github/fretlink/ansible-postgresql-role.git/commitdiff
Allow to set options for barman connectivity
authorThéophile Helleboid <theophile.helleboid@captaintrain.com>
Thu, 2 May 2019 15:24:20 +0000 (17:24 +0200)
committerThéophile Helleboid <theophile.helleboid@captaintrain.com>
Fri, 3 May 2019 12:10:05 +0000 (14:10 +0200)
- 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)

README.md
defaults/main.yml
tasks/postgres-standby-barman.yml
templates/postgresql.10.conf.j2
templates/standby-clone.sh.j2

index 5482bc60947065f9223d16a8c52ccd12af97b96c..050fb65fc76ea874332b3cbdca0984d68ef4967e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -78,6 +78,13 @@ postgres_replication_hosts:
 
 # Ansible related Configuration
 postgres_become_method: su  # Optional
+
+# Barman connectivity
+postgres_barman_server: barman.example.com  # Required if at least one server has archive_enabled enabled
+postgres_barman_rsync_enabled: False        # Optional
+postgres_barman_rsync_options: ''           # Optional
+postgres_barman_remote_user: barman         # Optional
+postgres_barman_path_prefix: '~'            # Optional, required if using rsync
 ```
 
 #### Testing
index 5876e943ffd44b9674835ed7315cf468861ad9b6..587779c2e07709f12467360f48811cc0ad5a0932 100644 (file)
@@ -7,6 +7,7 @@ postgres_clusters: []
 # postgres_pgbadger_server: ~
 postgres_backup_enabled: false
 postgres_barman_rsync_enabled: false
+postgres_barman_remote_user: barman
 
 postgres_become_method: su
 #------------------------------------------------------------#
@@ -18,4 +19,3 @@ postgres_locale_system: C.UTF-8
 postgres_locale_formats: C.UTF-8
 postgres_text_search_config: pg_catalog.english
 #------------------------------------------------------------#
-
index 65e87a6f87edc2d324e3cc076428dbe15e691e13..6a94b755d6fd77073c3a6bff4d0c10967f311dc0 100644 (file)
@@ -1,4 +1,16 @@
 ---
+- name: Compute barman remote URL
+  set_fact:
+    barman_remote_url: "{{ scheme }}{{ user }}{{ server }}{{ delimiter }}{{ path }}"
+    rsync_options: "{{ postgres_barman_rsync_options | default('') }}{{ rsync_password_file }}"
+  vars:
+    scheme: "{{ postgres_barman_rsync_enabled | ternary('rsync://', '') }}"
+    user: "{{ postgres_barman_remote_user is defined | ternary(postgres_barman_remote_user + '@', '') }}"
+    server: "{{ postgres_barman_server }}"
+    delimiter: "{{ postgres_barman_rsync_enabled | ternary('', ':')}}"
+    path: "{{ postgres_barman_path_prefix | default('~') }}"
+    rsync_password_file: "{{ postgres_barman_rsync_enabled | ternary(' --password-file=/var/lib/postgresql/.rsync_pass ', '') }}"
+
 - name: Copy secondary script
   template: src=standby-clone.sh.j2 dest=/root/standby-clone-{{ postgres_version }}-{{ postgres_cluster_name }}.sh mode=0755
 
index 588020f572aa8947af9bf861ba685883312aba24..b07b22b4ba2a78b4e9db4c8422fa74fbc289eb9b 100644 (file)
@@ -228,7 +228,7 @@ wal_log_hints = on                  # also do full page writes of non-critical updates
 
 {% if postgres_archive_enabled %}
 archive_mode = on
-archive_command = 'rsync -a %p barman@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f'
+archive_command = 'rsync -a %p {{ postgres_barman_remote_user }}@{{ postgres_barman_server }}:/var/lib/barman/{{ barman_directory }}/incoming/%f'
 {% else %}
 archive_mode = off
 archive_command = ''
index 16a693029b1ea79135a01572c2299d7812ace345..2db44b6e5c7377b75a5f7bb79e555bae5d4d73e1 100755 (executable)
@@ -29,11 +29,8 @@ sudo -u postgres mkdir -p /var/lib/postgresql/{{ postgres_version }}/{{ postgres
 
 echo Get previous backup from backups server
 sudo -u postgres \
-  time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete \
-{% if postgres_barman_rsync_enabled|default(false) -%}
-  --password-file=/var/lib/postgresql/.rsync_pass \
-{%- endif %}
-  {% 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/ \
+  time rsync --progress -pvia --exclude='*.conf' --exclude='server.crt' --exclude='server.key' --delete {{ rsync_options }} \
+  {{ barman_remote_url }}/$BARMAN_DATABASE/base/$BARMAN_BACKUP_VERSION/data/ \
   /var/lib/postgresql/{{ postgres_version }}/{{ postgres_cluster_name }}/
 
 echo Restoring .conf and server certificate