2015-05-28 11:32:57 +02:00
|
|
|
---
|
|
|
|
- name: Give access to the remote postgresql client
|
2016-12-18 19:12:51 +01:00
|
|
|
lineinfile: name={{ psql_conf_dir }}/pg_hba.conf regexp="^host.* {{ item.0.name }} {{ item.0.user }} {{ item.1 }}.*$" line="host {{ item.0.name }} {{ item.0.user }} {{ item.1 }} md5"
|
2015-05-28 11:32:57 +02:00
|
|
|
with_subelements:
|
2016-03-07 17:43:37 +01:00
|
|
|
- '{{ psql_db_data | default([]) }}'
|
|
|
|
- allowed_hosts
|
2015-05-28 11:32:57 +02:00
|
|
|
when:
|
|
|
|
- psql_listen_on_ext_int
|
|
|
|
- psql_db_data is defined
|
|
|
|
- item.1 is defined
|
2016-07-12 16:19:48 +02:00
|
|
|
- not psql_force_ssl_client_connection
|
|
|
|
notify: Reload postgresql
|
2017-04-10 11:45:40 +02:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_db' ]
|
2016-07-12 16:19:48 +02:00
|
|
|
|
|
|
|
- name: Give access to the remote postgresql client, force ssl
|
2016-12-18 19:12:51 +01:00
|
|
|
lineinfile: name={{ psql_conf_dir }}/pg_hba.conf regexp="^host.* {{ item.0.name }} {{ item.0.user }} {{ item.1 }}.*$" line="hostssl {{ item.0.name }} {{ item.0.user }} {{ item.1 }} md5"
|
2016-07-12 16:19:48 +02:00
|
|
|
with_subelements:
|
|
|
|
- '{{ psql_db_data | default([]) }}'
|
|
|
|
- allowed_hosts
|
|
|
|
when:
|
|
|
|
- psql_listen_on_ext_int
|
|
|
|
- psql_db_data is defined
|
|
|
|
- item.1 is defined
|
|
|
|
- psql_force_ssl_client_connection
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: Reload postgresql
|
2017-04-10 11:45:40 +02:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_db' ]
|
2016-04-07 18:12:21 +02:00
|
|
|
|
|
|
|
# No conditionals, it is needed to perform base backups when the WAL archive is active
|
|
|
|
- name: Give local access with replication privileges to the postgres user
|
2016-12-18 19:12:51 +01:00
|
|
|
lineinfile: name={{ psql_conf_dir }}/pg_hba.conf regexp="^local replication postgres peer" line="local replication postgres peer"
|
2016-04-07 18:12:21 +02:00
|
|
|
notify: Reload postgresql
|
2017-04-10 11:45:40 +02:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_db' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
2016-03-07 19:18:46 +01:00
|
|
|
- name: Set the postgresql listen port
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=port value="{{ psql_db_port }}"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2016-03-07 19:18:46 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
|
|
|
|
2015-05-28 11:32:57 +02:00
|
|
|
- name: We want postgres listen on the public IP
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'*'"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2015-05-28 11:32:57 +02:00
|
|
|
when:
|
|
|
|
- psql_listen_on_ext_int
|
|
|
|
- psql_db_data is defined
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: If postgresql is only accessed from localhost make it listen only on the localhost interface
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'localhost'"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2015-05-28 11:32:57 +02:00
|
|
|
when:
|
|
|
|
- not psql_listen_on_ext_int
|
|
|
|
- psql_db_data is defined
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: Log the connections
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_connections value="on"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2015-06-22 14:49:59 +02:00
|
|
|
when: psql_db_data is defined
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: Log the disconnections
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_disconnections value="on"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2015-06-22 14:49:59 +02:00
|
|
|
when: psql_db_data is defined
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: Log the hostnames
|
2016-12-18 19:12:51 +01:00
|
|
|
action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_hostname value="on"
|
2016-06-07 18:26:14 +02:00
|
|
|
register: restart_postgresql
|
2015-05-28 11:32:57 +02:00
|
|
|
when:
|
|
|
|
- psql_listen_on_ext_int
|
|
|
|
- psql_db_data is defined
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: Set the correct permissions to the postgresql files
|
2016-12-18 19:12:51 +01:00
|
|
|
file: dest={{ psql_conf_dir }}/{{ item }} owner=root group=postgres mode=0640
|
2015-05-28 11:32:57 +02:00
|
|
|
with_items:
|
|
|
|
- pg_hba.conf
|
|
|
|
- postgresql.conf
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
2016-06-07 18:26:14 +02:00
|
|
|
- name: Restart the postgresql server after changing parameters that need a restart
|
|
|
|
service: name=postgresql state=restarted
|
|
|
|
when:
|
|
|
|
- postgresql_enabled
|
2016-06-27 13:38:11 +02:00
|
|
|
- ( restart_postgresql is defined ) and ( restart_postgresql | changed )
|
2016-06-07 18:26:14 +02:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ]
|