---
# file: roles/postgres/tasks/configuration.yml

- name: "config file {{ pg_data_directory }}/postgresql.conf"
  template:
    src: "postgresql.conf.j2"
    dest: "{{ pg_data_directory }}/postgresql.conf"
    owner: postgres
    group: postgres
    backup: yes
    mode: 0600
  notify: reload postgres
  tags: postgres

- name: "duplicate config to /etc/postgresql/{{ pg_version }}/{{ pg_cluster_name }}/postgresql.conf"
  template:
    src: "postgresql.conf.j2"
    dest: "/etc/postgresql/{{ pg_version }}/{{ pg_cluster_name }}/postgresql.conf"
    owner: postgres
    group: postgres
    backup: yes
    mode: 0600
  notify: reload postgres
  when: not ansible_check_mode
  tags: postgres

- name: "{{ pg_configuration_file_restart_required }}"
  template:
    src: "restart_required.conf"
    dest: "{{ pg_configuration_file_restart_required }}"
    owner: postgres
    group: postgres
    backup: yes
    mode: 0600
  notify: restart postgres
  tags: postgres

- name: "{{ pg_configuration_file_restart_required_extra_location }}"
  template:
    src: "restart_required.conf"
    dest: "{{ pg_configuration_file_restart_required_extra_location }}"
    owner: postgres
    group: postgres
    backup: yes
    mode: 0600
  notify: restart postgres
  when: pg_configuration_file_restart_required_extra_location is defined
  tags: postgres

- name: "logging directory"
  file:
    path: '{{ pg_log_directory }}'
    state: directory
    mode: 0755
    owner: postgres
    group: postgres
  notify: reload postgres
  when: pg_logging
  tags: postgres

- name: "postgres user .bash_profile"
  template:
    src: postgres_bash_profile
    dest: /var/lib/postgresql/.bash_profile
    owner: postgres
    group: postgres
  tags: postgres

- name: "{{ pg_data_directory }}/pg_hba.conf"
  template:
    backup: yes
    src: pg_hba.conf
    dest: "{{ pg_data_directory }}/pg_hba.conf"
    owner: postgres
    group: postgres
    mode: 0600
  notify: reload postgres
  tags:
    - postgres
    - pg_hba

- name: "duplicate config to /etc/postgresql/{{ pg_version }}/{{ pg_cluster_name }}/pg_hba.conf"
  template:
    backup: yes
    src: pg_hba.conf
    dest: "/etc/postgresql/{{ pg_version }}/{{ pg_cluster_name }}/pg_hba.conf"
    owner: postgres
    group: postgres
    mode: 0600
  notify: reload postgres
  tags:
    - postgres
    - pg_hba
