1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 - name: apt update if needed
6 ansible.builtin.meta: flush_handlers
8 - name: Install PostgreSQL server package and psycopg2
12 - "{{ arvados_postgresql_package }}"
15 - name: Find pg_hba.conf file
16 when: arvados_postgresql_hba_file is falsy
19 community.postgresql.postgresql_query:
22 register: pg_hba_query
24 - name: Create pg_hba.conf entries
25 when: arvados_postgresql_hba_databases is truthy and arvados_postgresql_hba_users is truthy
27 loop: "{{ arvados_postgresql_hba_sources }}"
28 community.postgresql.postgresql_pg_hba:
29 dest: "{{ arvados_postgresql_hba_file or pg_hba_query.query_result.0.hba_file }}"
30 contype: "{{ arvados_postgresql_hba_contype }}"
31 databases: "{{ arvados_postgresql_hba_databases }}"
32 method: "{{ arvados_postgresql_hba_method }}"
33 users: "{{ arvados_postgresql_hba_users }}"
35 register: pg_hba_entries
37 - name: Write PostgreSQL conf.d file
38 when: arvados_postgresql_config is truthy
41 conf_dir: "{{ (arvados_postgresql_hba_file or pg_hba_query.query_result.0.hba_file)|dirname }}"
42 ansible.builtin.template:
43 src: arvados-ansible.conf.j2
44 dest: "{{ arvados_postgresql_config_path or (conf_dir, 'conf.d', 'arvados-ansible.conf')|path_join }}"
48 register: arvados_postgresql_config_update
50 - name: Set up PostgreSQL service
52 ansible.builtin.systemd_service:
53 name: "postgresql@{{ (arvados_postgresql_hba_file or pg_hba_query.query_result.0.hba_file)|dirname|relpath('/etc/postgresql')|replace('/', '-') }}.service"
54 state: "{{ 'restarted' if arvados_postgresql_config_update.changed else 'reloaded' if pg_hba_entries.changed else 'started' }}"