diff --git a/roles/setup_barman/tasks/configure_pg_backup.yml b/roles/setup_barman/tasks/configure_pg_backup.yml index 4f743d77a..b63bda3cb 100644 --- a/roles/setup_barman/tasks/configure_pg_backup.yml +++ b/roles/setup_barman/tasks/configure_pg_backup.yml @@ -14,7 +14,21 @@ _barman_host: "{{ _barman_server_info[0].inventory_hostname }}" when: use_hostname|bool -- name: Ensure wal_level is configured to replica +- name: Get wal_level value + community.postgresql.postgresql_query: + query: >- + SELECT setting FROM pg_settings + WHERE name = 'wal_level' + port: "{{ pg_port }}" + db: "{{ pg_database }}" + login_user: "{{ pg_owner }}" + login_unix_socket: "{{ pg_unix_socket_directories[0] }}" + no_log: "{{ disable_logging }}" + become: true + become_user: "{{ pg_owner }}" + register: wal_level_result + +- name: Ensure wal_level is configured to replica if needed include_role: name: manage_dbserver tasks_from: manage_postgres_params @@ -23,6 +37,8 @@ - name: wal_level value: "replica" no_log: "{{ disable_logging }}" + when: + - wal_level_result.query_result[0].setting not in ['replica', 'logical'] - name: Ensure the replication slot barman exists include_role: diff --git a/roles/setup_barman/tasks/setup_barman.yml b/roles/setup_barman/tasks/setup_barman.yml index dd412dbf3..fbf67c765 100644 --- a/roles/setup_barman/tasks/setup_barman.yml +++ b/roles/setup_barman/tasks/setup_barman.yml @@ -5,7 +5,7 @@ os: "{{ ansible_distribution | replace('RedHat', 'RHEL') }}{{ ansible_distribution_major_version }}" - name: Reference pg_type variables - include_vars: "{{ pg_type }}.yml" + include_vars: "{{ pg_type }}_{{ ansible_os_family }}.yml" - name: Set barman_backup_method set_fact: diff --git a/roles/setup_barman/tasks/update_pg_hba.yml b/roles/setup_barman/tasks/update_pg_hba.yml index 4704722b3..5fd1e6a8a 100644 --- a/roles/setup_barman/tasks/update_pg_hba.yml +++ b/roles/setup_barman/tasks/update_pg_hba.yml @@ -9,6 +9,12 @@ 'databases': 'postgres', 'contype': 'hostssl', 'source': '{{ hostvars[inventory_hostname].barman_server_private_ip | default("127.0.0.1") }}/32' + }, + { + 'users': 'barman', + 'databases': 'postgres', + 'contype': 'host', + 'source': '{{ hostvars[inventory_hostname].barman_server_private_ip | default("127.0.0.1") }}/32' } ] @@ -21,6 +27,12 @@ 'databases': 'replication', 'contype': 'hostssl', 'source': '{{ hostvars[inventory_hostname].barman_server_private_ip }}/32' + }, + { + 'users': 'barman', + 'databases': 'replication', + 'contype': 'host', + 'source': '{{ hostvars[inventory_hostname].barman_server_private_ip }}/32' } ] when: diff --git a/roles/setup_barman/vars/EPAS.yml b/roles/setup_barman/vars/EPAS_Debian.yml similarity index 54% rename from roles/setup_barman/vars/EPAS.yml rename to roles/setup_barman/vars/EPAS_Debian.yml index 7b55f8046..e58666512 100644 --- a/roles/setup_barman/vars/EPAS.yml +++ b/roles/setup_barman/vars/EPAS_Debian.yml @@ -3,3 +3,6 @@ pg_owner: enterprisedb pg_port: 5444 pg_bin_path: "/usr/edb/as{{ pg_version }}/bin" +pg_database: "postgres" +pg_unix_socket_directories: + - "/var/run/edb-as" diff --git a/roles/setup_barman/vars/EPAS_RedHat.yml b/roles/setup_barman/vars/EPAS_RedHat.yml new file mode 100644 index 000000000..2c4d05c0f --- /dev/null +++ b/roles/setup_barman/vars/EPAS_RedHat.yml @@ -0,0 +1,8 @@ +--- + +pg_owner: enterprisedb +pg_port: 5444 +pg_bin_path: "/usr/edb/as{{ pg_version }}/bin" +pg_database: "postgres" +pg_unix_socket_directories: + - "/var/run/edb/as{{ pg_version }}" diff --git a/roles/setup_barman/vars/PG.yml b/roles/setup_barman/vars/PG_Debian.yml similarity index 51% rename from roles/setup_barman/vars/PG.yml rename to roles/setup_barman/vars/PG_Debian.yml index 1a945d9f7..4712dbd18 100644 --- a/roles/setup_barman/vars/PG.yml +++ b/roles/setup_barman/vars/PG_Debian.yml @@ -3,3 +3,6 @@ pg_owner: postgres pg_port: 5432 pg_bin_path: "/usr/pgsql{{ pg_version }}/bin" +pg_database: "postgres" +pg_unix_socket_directories: + - "/var/run/postgresql" diff --git a/roles/setup_barman/vars/PG_RedHat.yml b/roles/setup_barman/vars/PG_RedHat.yml new file mode 100644 index 000000000..4712dbd18 --- /dev/null +++ b/roles/setup_barman/vars/PG_RedHat.yml @@ -0,0 +1,8 @@ +--- + +pg_owner: postgres +pg_port: 5432 +pg_bin_path: "/usr/pgsql{{ pg_version }}/bin" +pg_database: "postgres" +pg_unix_socket_directories: + - "/var/run/postgresql" diff --git a/tests/cases/setup_barman/playbook.yml b/tests/cases/setup_barman/playbook.yml index e5b1fa344..ffdb79a87 100644 --- a/tests/cases/setup_barman/playbook.yml +++ b/tests/cases/setup_barman/playbook.yml @@ -19,6 +19,9 @@ - name: Initialize the user defined variables set_fact: disable_logging: false + pg_postgres_conf_params: + - name: wal_level + value: logical roles: - role: setup_repo @@ -27,7 +30,9 @@ when: "'install_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" - role: init_dbserver when: "'init_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" + - role: manage_dbserver + when: "'manage_dbserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" - role: setup_barmanserver when: "'setup_barmanserver' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" - role: setup_barman - when: "'setup_barman' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" \ No newline at end of file + when: "'setup_barman' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)" diff --git a/tests/tests/test_setup_barman.py b/tests/tests/test_setup_barman.py index 64008b7f5..32766172e 100644 --- a/tests/tests/test_setup_barman.py +++ b/tests/tests/test_setup_barman.py @@ -17,7 +17,7 @@ def test_setup_barman_backup(): with host.sudo(barman_user): cmd = host.run('barman list-server') result = cmd.stdout.strip() - + assert "primary1" in result, \ "%s backup server was not configured correctly" % "primary1" @@ -30,7 +30,7 @@ def test_setup_barman_home_dir(): with host.sudo(barman_user): cmd = host.run('barman show-server primary1-main | grep barman_home') result = cmd.stdout.strip() - + assert barman_home in result, \ "%s directory was not configured correctly" % barman_home @@ -43,7 +43,7 @@ def test_setup_barman_status(): with host.sudo(barman_user): cmd = host.run('barman status primary1-main | grep Active') result = cmd.stdout.strip() - + assert "True" in result, \ "primary1-main's server status is not active" @@ -59,7 +59,7 @@ def test_setup_barman_user(): host= get_primary() socket_dir = get_pg_unix_socket_dir() - + with host.sudo(pg_user): query = "Select * from pg_user where usename = '%s'" % barman_user cmd = host.run('psql -At -p %s -h %s -c "%s" postgres' % (port, socket_dir, query)) @@ -68,6 +68,31 @@ def test_setup_barman_user(): assert len(result) > 0, \ "Barman user does not exist in primary database" +def test_setup_barman_logical_wal_level(): + # Make sure setup_barman does not override wal_level if it has been + # previously configured to 'logical'. + ansible_vars = load_ansible_vars() + barman_user = ansible_vars['barman_user'] + port = '5432' + pg_user = 'postgres' + + if get_pg_type() == 'EPAS': + pg_user = 'enterprisedb' + port = '5444' + + host= get_primary() + socket_dir = get_pg_unix_socket_dir() + + with host.sudo(pg_user): + query = "SELECT setting FROM pg_settings WHERE name = 'wal_level'" + cmd = host.run( + 'psql -At -p %s -h %s -c "%s" postgres' % (port, socket_dir, query) + ) + result = cmd.stdout.strip() + + assert result == 'logical', \ + "wal_level should be set to 'logical'" + def test_setup_barman_backup(): ansible_vars = load_ansible_vars() barman_user = ansible_vars['barman_user'] @@ -80,6 +105,3 @@ def test_setup_barman_backup(): assert len(result) > 0, \ "Backup for primary1-main's server has failed" - - -