---
- block:
    - name: Setup ssl in the postgresql configuration
      become: True
      become_user: postgres
      action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key={{ item.name }} value="'{{ item.value }}'"
      with_items: '{{ psql_conf_ssl_parameters }}'
      notify: Restart postgresql

    - name: Create the pki directory to store the postgresql key
      file: dest=/etc/pki/postgresql state=directory owner=postgres group=postgres mode=0750

    - name: Create a postgres accessible ssl key file if it does not exist
      copy: src=/var/lib/acme/live/{{ ansible_fqdn }}/privkey dest=/etc/pki/postgresql/postgresql.key owner=postgres group=postgres mode=0400 remote_src=True

  when: psql_enable_ssl
  tags: [ 'postgresql', 'postgres', 'pg_conf' ]