- include: postgres-database.yml
postgres_dbname={{ item.1.dbname }}
postgres_owner={{ item.1.owner }}
+ postgres_extensions={{ item.1.extensions|default([]) }}
postgres_port={{ item.0.port }}
with_subelements:
- "{{ postgres_clusters }}"
src: /var/lib/postgresql/.ssh/id_rsa.pub
register: db_server_pub_key
+- name: Check if barman is installed on barman server
+ getent:
+ database: passwd
+ key: "barman"
+ delegate_to: "{{ postgres_barman_server_public|default(postgres_barman_server) }}"
+ when: postgres_barman_server is defined
+ register: barman_user_exists
+ ignore_errors: true
+ changed_when: false
+
- name: Allow SSH access on barman server
authorized_key:
user: "barman"
key: "{{ db_server_pub_key['content']|b64decode }}"
state: present
delegate_to: "{{ postgres_barman_server_public|default(postgres_barman_server) }}"
- when: postgres_barman_server is defined
+ when:
+ - postgres_barman_server is defined
+ - barman_user_exists is succeeded
- name: Copy logrotate configuration for postgresql
template: src=logrotate-postgresql-common.j2 dest=/etc/logrotate.d/postgresql-common owner=root group=root mode=0644
--- /dev/null
+---
+- name: "Install required packages for 'postgres_ext' ansible module"
+ apt:
+ name:
+ - libpq-dev
+ - python-psycopg2
+
+- name: Install system dependencies of extensions
+ apt:
+ name: "{{ postgres_extension.apt_deps | default([]) }}"
+ cache_valid_time: 86400
+
+- name: "CREATE EXTENSION on database {{ postgres_dbname }}"
+ become: true
+ become_user: postgres
+ become_method: su
+ postgresql_ext:
+ name: "{{ postgres_extension_name }}"
+ db: "{{ postgres_dbname }}"
+ port: "{{ postgres_port }}"
+ loop: "{{ postgres_extension.names | default([]) }}"
+ loop_control:
+ loop_var: postgres_extension_name
owner: "{{ postgres_owner }}"
when:
- postgres_up.rc == 0
+
+- name: Create database extensions
+ include_tasks: postgres-database-extensions.yml
+ loop: "{{ postgres_extensions| default([]) }}"
+ loop_control:
+ loop_var: postgres_extension
+ when: postgres_up.rc == 0