2015-05-28 11:32:57 +02:00
|
|
|
---
|
|
|
|
#
|
|
|
|
# To give postgresql access to remote clients you need to define something like that:
|
|
|
|
#
|
|
|
|
# psql_db_data:
|
|
|
|
# - { name: 'db_name', user: 'db_user', pwd: 'db_pwd', allowed_hosts: [ '146.48.123.17/32', '146.48.122.110/32' ] }
|
|
|
|
#
|
|
|
|
- name: Give access to the remote postgresql client
|
|
|
|
lineinfile: name=/etc/postgresql/{{ psql_version }}/main/pg_hba.conf regexp="^host {{ item.0.name }} {{ item.0.user }} {{ item.1 }}.*$" line="host {{ item.0.name }} {{ item.0.user }} {{ item.1 }} md5"
|
|
|
|
with_subelements:
|
2016-03-02 16:44:43 +01:00
|
|
|
- '{{ psql_db_data }}'
|
|
|
|
- '{{ 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
|
|
|
|
notify: Reload postgresql
|
2016-03-02 16:44:43 +01:00
|
|
|
tags: [ 'postgresql', 'postgres', 'pg_hba' ]
|
2015-05-28 11:32:57 +02:00
|
|
|
|
|
|
|
- name: We want postgres listen on the public IP
|
2015-07-13 14:17:42 +02:00
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key=listen_addresses value="'*'"
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: Restart postgresql
|
|
|
|
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
|
2015-07-13 14:17:42 +02:00
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key=listen_addresses value="'localhost'"
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: Restart postgresql
|
|
|
|
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
|
2015-06-22 14:49:59 +02:00
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key=log_connections value="on"
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: 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
|
2015-06-22 14:49:59 +02:00
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key=log_disconnections value="on"
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: 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
|
2015-06-22 14:49:59 +02:00
|
|
|
action: configfile path=/etc/postgresql/{{ psql_version }}/main/postgresql.conf key=log_hostname value="on"
|
2015-05-28 11:32:57 +02:00
|
|
|
notify: Restart postgresql
|
|
|
|
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
|
|
|
|
file: dest=/etc/postgresql/{{ psql_version }}/main/{{ item }} owner=root group=postgres mode=0640
|
|
|
|
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
|
|
|
|