xoxys.postgres/tasks/install.yml
Robert Kaussow 1031ea6778
All checks were successful
continuous-integration/drone/push Build is passing
refactor: use generic ansible modules service and package
2021-06-05 15:30:39 +02:00

49 lines
1.4 KiB
YAML

---
- block:
- name: Install PostgreSQL
package:
name: "{{ item }}"
state: present
loop: "{{ __postgres_packages }}"
- name: Ensure data directory exists
file:
path: "{{ __postgres_data_dir }}"
owner: "{{ postgres_user }}"
group: "{{ postgres_group }}"
state: directory
mode: 0700
- name: Setup custom systemd service
template:
src: etc/systemd/system/postgresql.service.j2
dest: "/etc/systemd/system/{{ __postgres_daemon }}.service"
mode: 0644
notify: __postgres_restart
register: __postgres_systemd
- name: Force systemd to re-read configs
service:
daemon_reload: True
when: __postgres_systemd.changed
- name: Check if database is initialized
stat:
path: "{{ __postgres_data_dir }}/PG_VERSION"
register: __pgdata_dir_version
- name: Ensure database is initialized
command: "/usr/pgsql-{{ __postgres_version }}/bin/postgresql-{{ __postgres_version }}-setup initdb"
when: not __pgdata_dir_version.stat.exists
- name: Override default pg_hba.conf with a clean one
template:
src: templates/postgresql/data/pg_hba.conf.j2
dest: "{{ __postgres_config_path }}/pg_hba.conf"
mode: 0644
when:
- not __pgdata_dir_version.stat.exists
- postgres_clean_hba_file | bool
become: True
become_user: root