]> git.arvados.org - arvados.git/blob - tools/ansible/roles/arvados_postgresql/tasks/main.yml
Merge branch '22922-bundler-2.5'
[arvados.git] / tools / ansible / roles / arvados_postgresql / tasks / main.yml
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 - name: apt update if needed
6   ansible.builtin.meta: flush_handlers
7
8 - name: Install PostgreSQL server package and psycopg2
9   become: yes
10   ansible.builtin.apt:
11     name:
12       - "{{ arvados_postgresql_package }}"
13       - python3-psycopg2
14
15 - name: Find pg_hba.conf file
16   when: arvados_postgresql_hba_file is falsy
17   become: yes
18   become_user: postgres
19   community.postgresql.postgresql_query:
20     login_db: postgres
21     query: SHOW hba_file;
22   register: pg_hba_query
23
24 - name: Create pg_hba.conf entries
25   when: arvados_postgresql_hba_databases is truthy and arvados_postgresql_hba_users is truthy
26   become: true
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 }}"
34     source: "{{ item }}"
35   register: pg_hba_entries
36
37 - name: Write PostgreSQL conf.d file
38   when: arvados_postgresql_config is truthy
39   become: true
40   vars:
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 }}"
45     owner: root
46     group: root
47     mode: 0644
48   register: arvados_postgresql_config_update
49
50 - name: Set up PostgreSQL service
51   become: yes
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' }}"
55     enabled: yes