From be46ede7420159f6febc87ced7efe6218e620341 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Sun, 18 Oct 2020 20:23:29 +0200 Subject: [PATCH] Move the tasks that do not depend from psql_db_data --- tasks/configure-access.yml | 104 ----------------------------------- tasks/postgresql-config.yml | 105 +++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 105 deletions(-) diff --git a/tasks/configure-access.yml b/tasks/configure-access.yml index 7dad6f9..1245cd4 100644 --- a/tasks/configure-access.yml +++ b/tasks/configure-access.yml @@ -33,58 +33,6 @@ notify: Reload postgresql tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_db' ] - - name: Set the postgresql listen port - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=port value="{{ psql_db_port }}" - register: restart_postgresql - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: We want postgres listen on the public IP - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'*'" - register: restart_postgresql - when: - - psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: If postgresql is only accessed from localhost make it listen only on the localhost interface - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'localhost'" - register: restart_postgresql - when: - - not psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the connections - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_connections value="on" - register: restart_postgresql - when: psql_db_data is defined - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the disconnections - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_disconnections value="on" - register: restart_postgresql - when: psql_db_data is defined - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the hostnames - action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_hostname value="on" - register: restart_postgresql - when: - - psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Set the correct permissions to the postgresql files - file: dest={{ psql_conf_dir }}/{{ item }} owner=root group=postgres mode=0640 - with_items: - - pg_hba.conf - - postgresql.conf - tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] - - - name: Restart the postgresql server after changing parameters that need a restart - service: name=postgresql state=restarted - when: - - restart_postgresql is changed - ignore_errors: True - tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] - when: ansible_distribution_file_variety == "Debian" - name: Configure accesses on EL @@ -132,56 +80,4 @@ notify: Reload postgresql tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_db' ] - - name: Set the postgresql listen port - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=port value="{{ psql_db_port }}" - register: restart_postgresql - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: We want postgres listen on the public IP - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=listen_addresses value="'*'" - register: restart_postgresql - when: - - psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: If postgresql is only accessed from localhost make it listen only on the localhost interface - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=listen_addresses value="'localhost'" - register: restart_postgresql - when: - - not psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the connections - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_connections value="on" - register: restart_postgresql - when: psql_db_data is defined - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the disconnections - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_disconnections value="on" - register: restart_postgresql - when: psql_db_data is defined - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Log the hostnames - action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_hostname value="on" - register: restart_postgresql - when: - - psql_listen_on_ext_int - tags: [ 'postgresql', 'postgres', 'pg_conf' ] - - - name: Set the correct permissions to the postgresql files - file: dest={{ psql_el_conf_dir }}/{{ item }} owner=root group=postgres mode=0640 - with_items: - - pg_hba.conf - - postgresql.conf - tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] - - - name: Restart the postgresql server after changing parameters that need a restart - service: name='postgresql-{{ psql_version }}' state=restarted - when: - - restart_postgresql is changed - ignore_errors: True - tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] - when: ansible_distribution_file_variety == "RedHat" diff --git a/tasks/postgresql-config.yml b/tasks/postgresql-config.yml index 372934d..6787b5d 100644 --- a/tasks/postgresql-config.yml +++ b/tasks/postgresql-config.yml @@ -61,6 +61,58 @@ notify: Reload postgresql tags: [ 'postgresql', 'postgres', 'pg_conf', 'pg_conf_autovacuum' ] + - name: Set the postgresql listen port + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=port value="{{ psql_db_port }}" + register: restart_postgresql + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: We want postgres listen on the public IP + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'*'" + register: restart_postgresql + when: + - psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: If postgresql is only accessed from localhost make it listen only on the localhost interface + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=listen_addresses value="'localhost'" + register: restart_postgresql + when: + - not psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the connections + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_connections value="on" + register: restart_postgresql + when: psql_db_data is defined + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the disconnections + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_disconnections value="on" + register: restart_postgresql + when: psql_db_data is defined + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the hostnames + action: configfile path={{ psql_conf_dir }}/postgresql.conf key=log_hostname value="on" + register: restart_postgresql + when: + - psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Set the correct permissions to the postgresql files + file: dest={{ psql_conf_dir }}/{{ item }} owner=root group=postgres mode=0640 + with_items: + - pg_hba.conf + - postgresql.conf + tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] + + - name: Restart the postgresql server after changing parameters that need a restart + service: name=postgresql state=restarted + when: + - restart_postgresql is changed + ignore_errors: True + tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] + when: ansible_distribution_file_variety == "Debian" - name: Data directory for EL @@ -107,7 +159,6 @@ - name: Configuration of EL systems block: - - name: Create the postgresql log directory file: dest={{ psql_log_dir }} state=directory owner=postgres group=postgres mode='0750' @@ -147,4 +198,56 @@ notify: Reload postgresql tags: [ 'postgresql', 'postgres', 'pg_conf', 'pg_conf_autovacuum' ] + - name: Set the postgresql listen port + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=port value="{{ psql_db_port }}" + register: restart_postgresql + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: We want postgres listen on the public IP + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=listen_addresses value="'*'" + register: restart_postgresql + when: + - psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: If postgresql is only accessed from localhost make it listen only on the localhost interface + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=listen_addresses value="'localhost'" + register: restart_postgresql + when: + - not psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the connections + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_connections value="on" + register: restart_postgresql + when: psql_db_data is defined + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the disconnections + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_disconnections value="on" + register: restart_postgresql + when: psql_db_data is defined + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Log the hostnames + action: configfile path={{ psql_el_conf_dir }}/postgresql.conf key=log_hostname value="on" + register: restart_postgresql + when: + - psql_listen_on_ext_int + tags: [ 'postgresql', 'postgres', 'pg_conf' ] + + - name: Set the correct permissions to the postgresql files + file: dest={{ psql_el_conf_dir }}/{{ item }} owner=root group=postgres mode=0640 + with_items: + - pg_hba.conf + - postgresql.conf + tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] + + - name: Restart the postgresql server after changing parameters that need a restart + service: name='postgresql-{{ psql_version }}' state=restarted + when: + - restart_postgresql is changed + ignore_errors: True + tags: [ 'postgresql', 'postgres', 'pg_hba', 'pg_conf' ] + when: ansible_distribution_file_variety == "RedHat"