---
- name: Override PostgreSQL systemd unit
  template:
    src: postgresql.service.j2
    dest: /etc/systemd/system/multi-user.target.wants/postgresql.service
    force: yes
  notify:
    - reload systemd
    - restart postgresql

- name: Allow conf.d/*.conf files to be included in PostgreSQL configuration
  lineinfile:
    name: "/etc/postgresql/{{postgresql_version}}/main/postgresql.conf"
    line: include_dir = 'conf.d'
  notify: restart postgresql

- name: Create conf.d directory
  file:
    name: "/etc/postgresql/{{postgresql_version}}/main/conf.d/"
    state: directory
    owner: postgres
    group: postgres
    mode: "0755"

- name: Copy PostgreSQL config file
  template:
    src: postgresql.conf.j2
    dest: "/etc/postgresql/{{postgresql_version}}/main/conf.d/zz-evolinux.conf"
    owner: postgres
    group: postgres
    mode: "0644"
  notify: restart postgresql

- meta: flush_handlers
