diff options
-rw-r--r-- | tasks/main.yml | 1 | ||||
-rw-r--r-- | tasks/postgres-common-postinstall.yml | 14 | ||||
-rw-r--r-- | tasks/postgres-database-extensions.yml | 23 | ||||
-rw-r--r-- | tasks/postgres-database.yml | 7 |
4 files changed, 44 insertions, 1 deletions
diff --git a/tasks/main.yml b/tasks/main.yml index 2fa7883..3d1892c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml | |||
@@ -46,6 +46,7 @@ | |||
46 | - include: postgres-database.yml | 46 | - include: postgres-database.yml |
47 | postgres_dbname={{ item.1.dbname }} | 47 | postgres_dbname={{ item.1.dbname }} |
48 | postgres_owner={{ item.1.owner }} | 48 | postgres_owner={{ item.1.owner }} |
49 | postgres_extensions={{ item.1.extensions|default([]) }} | ||
49 | postgres_port={{ item.0.port }} | 50 | postgres_port={{ item.0.port }} |
50 | with_subelements: | 51 | with_subelements: |
51 | - "{{ postgres_clusters }}" | 52 | - "{{ postgres_clusters }}" |
diff --git a/tasks/postgres-common-postinstall.yml b/tasks/postgres-common-postinstall.yml index 277fafd..715782c 100644 --- a/tasks/postgres-common-postinstall.yml +++ b/tasks/postgres-common-postinstall.yml | |||
@@ -15,13 +15,25 @@ | |||
15 | src: /var/lib/postgresql/.ssh/id_rsa.pub | 15 | src: /var/lib/postgresql/.ssh/id_rsa.pub |
16 | register: db_server_pub_key | 16 | register: db_server_pub_key |
17 | 17 | ||
18 | - name: Check if barman is installed on barman server | ||
19 | getent: | ||
20 | database: passwd | ||
21 | key: "barman" | ||
22 | delegate_to: "{{ postgres_barman_server_public|default(postgres_barman_server) }}" | ||
23 | when: postgres_barman_server is defined | ||
24 | register: barman_user_exists | ||
25 | ignore_errors: true | ||
26 | changed_when: false | ||
27 | |||
18 | - name: Allow SSH access on barman server | 28 | - name: Allow SSH access on barman server |
19 | authorized_key: | 29 | authorized_key: |
20 | user: "barman" | 30 | user: "barman" |
21 | key: "{{ db_server_pub_key['content']|b64decode }}" | 31 | key: "{{ db_server_pub_key['content']|b64decode }}" |
22 | state: present | 32 | state: present |
23 | delegate_to: "{{ postgres_barman_server_public|default(postgres_barman_server) }}" | 33 | delegate_to: "{{ postgres_barman_server_public|default(postgres_barman_server) }}" |
24 | when: postgres_barman_server is defined | 34 | when: |
35 | - postgres_barman_server is defined | ||
36 | - barman_user_exists is succeeded | ||
25 | 37 | ||
26 | - name: Copy logrotate configuration for postgresql | 38 | - name: Copy logrotate configuration for postgresql |
27 | template: src=logrotate-postgresql-common.j2 dest=/etc/logrotate.d/postgresql-common owner=root group=root mode=0644 | 39 | template: src=logrotate-postgresql-common.j2 dest=/etc/logrotate.d/postgresql-common owner=root group=root mode=0644 |
diff --git a/tasks/postgres-database-extensions.yml b/tasks/postgres-database-extensions.yml new file mode 100644 index 0000000..edc4e8d --- /dev/null +++ b/tasks/postgres-database-extensions.yml | |||
@@ -0,0 +1,23 @@ | |||
1 | --- | ||
2 | - name: "Install required packages for 'postgres_ext' ansible module" | ||
3 | apt: | ||
4 | name: | ||
5 | - libpq-dev | ||
6 | - python-psycopg2 | ||
7 | |||
8 | - name: Install system dependencies of extensions | ||
9 | apt: | ||
10 | name: "{{ postgres_extension.apt_deps | default([]) }}" | ||
11 | cache_valid_time: 86400 | ||
12 | |||
13 | - name: "CREATE EXTENSION on database {{ postgres_dbname }}" | ||
14 | become: true | ||
15 | become_user: postgres | ||
16 | become_method: su | ||
17 | postgresql_ext: | ||
18 | name: "{{ postgres_extension_name }}" | ||
19 | db: "{{ postgres_dbname }}" | ||
20 | port: "{{ postgres_port }}" | ||
21 | loop: "{{ postgres_extension.names | default([]) }}" | ||
22 | loop_control: | ||
23 | loop_var: postgres_extension_name | ||
diff --git a/tasks/postgres-database.yml b/tasks/postgres-database.yml index c7b09a8..c3537ea 100644 --- a/tasks/postgres-database.yml +++ b/tasks/postgres-database.yml | |||
@@ -18,3 +18,10 @@ | |||
18 | owner: "{{ postgres_owner }}" | 18 | owner: "{{ postgres_owner }}" |
19 | when: | 19 | when: |
20 | - postgres_up.rc == 0 | 20 | - postgres_up.rc == 0 |
21 | |||
22 | - name: Create database extensions | ||
23 | include_tasks: postgres-database-extensions.yml | ||
24 | loop: "{{ postgres_extensions| default([]) }}" | ||
25 | loop_control: | ||
26 | loop_var: postgres_extension | ||
27 | when: postgres_up.rc == 0 | ||