From 96d172ce67252ed3877a37dd18d01c771a320a7b Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 18 Dec 2023 13:00:20 +0100 Subject: [PATCH] Option to install the client only. --- defaults/main.yml | 1 + tasks/main.yml | 21 +++++++-- tasks/packages.yml | 38 ---------------- tasks/postgresql-packages.yml | 86 +++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 42 deletions(-) delete mode 100644 tasks/packages.yml create mode 100644 tasks/postgresql-packages.yml diff --git a/defaults/main.yml b/defaults/main.yml index e11eca7..4ea64b7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -10,6 +10,7 @@ postgresql_deb_repo_key: /etc/apt/keyrings/postgresql.asc postgresql_deb_repository_url: "http://apt.postgresql.org/pub/repos/apt/" postgresql_deb_repository_rel: "{{ ansible_lsb.codename }}-pgdg" psql_postgresql_install: true +postgresql_client_only: false psql_pkg_state: present postgresql_enabled: true psql_version: 16 diff --git a/tasks/main.yml b/tasks/main.yml index 411f849..8ebcbd8 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,7 +2,7 @@ - name: Postgresql external repository ansible.builtin.import_tasks: postgresql_org_repo.yml - name: Manage the postgresql packages - ansible.builtin.import_tasks: packages.yml + ansible.builtin.import_tasks: postgresql-packages.yml when: psql_postgresql_install - name: Manage the postgis packages ansible.builtin.import_tasks: postgis.yml @@ -11,41 +11,54 @@ ansible.builtin.import_tasks: postgresql-config-deb.yml when: - psql_postgresql_install + - not postgresql_client_only - ansible_distribution_file_variety == "Debian" - name: PostgreSQL configuration of EL systems ansible.builtin.import_tasks: postgresql-config-el.yml when: - psql_postgresql_install + - not postgresql_client_only - ansible_distribution_file_variety == "RedHat" - name: TLS setup ansible.builtin.import_tasks: postgresql-ssl-config.yml - when: psql_postgresql_install + when: + - psql_postgresql_install + - not postgresql_client_only - name: Kernel sysctl parameters ansible.builtin.import_tasks: psql-kernel-sharedmem.yml when: - psql_postgresql_install - psql_set_shared_memory + - not postgresql_client_only - name: Configure access to the databases ansible.builtin.import_tasks: configure-access.yml when: - psql_postgresql_install - psql_db_data is defined + - not postgresql_client_only - name: Service management ansible.builtin.import_tasks: postgresql-service-status.yml - when: psql_postgresql_install + when: + - psql_postgresql_install + - not postgresql_client_only - name: Manage the databases ansible.builtin.import_tasks: manage_pg_db.yml when: - psql_postgresql_install - psql_db_data is defined + - not postgresql_client_only - name: Streaming replication setup ansible.builtin.import_tasks: postgresql-streaming-replication.yml when: - postgresql_streaming_replication + - not postgresql_client_only - name: Local backups ansible.builtin.import_tasks: postgresql-backup.yml - when: psql_postgresql_install + when: + - psql_postgresql_install + - not postgresql_client_only - name: Letsencrypt hook ansible.builtin.import_tasks: postgresql-letsencrypt-acmetool.yml when: - postgresql_letsencrypt_managed + - not postgresql_client_only diff --git a/tasks/packages.yml b/tasks/packages.yml deleted file mode 100644 index e188574..0000000 --- a/tasks/packages.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -- block: - - name: install the postgresql packages - apt: pkg={{ postgresql_pkgs }} state={{ psql_pkg_state }} cache_valid_time=3600 - notify: Restart postgresql - - when: ansible_distribution_file_variety == "Debian" - tags: [ 'postgresql', 'postgres' ] - -- name: EL - block: - - name: install the postgresql packages from the pgdg repository - yum: pkg={{ psql_el_pgdg_packages }} state={{ psql_pkg_state }} - - - name: Init the db if needed - command: /usr/pgsql-{{ psql_version }}/bin/postgresql-{{ psql_version }}-setup initdb - args: - creates: '{{ psql_el_data_dir }}/postgresql.conf' - - when: - - not psql_el_install_scl_version - - ansible_distribution_file_variety == "RedHat" - tags: [ 'postgresql', 'postgres' ] - -- name: EL from SCL - block: - - name: install the postgresql scl packages - yum: pkg={{ psql_el_scl_packages }} state={{ psql_pkg_state }} - - - name: Init the db if needed - command: /opt/rh/rh-postgresql{{ psql_version }}/root/usr/bin/postgresql-setup --initdb - args: - creates: '{{ psql_el_data_dir }}/postgresql.conf' - - when: - - psql_el_install_scl_version - - ansible_distribution_file_variety == "RedHat" - tags: [ 'scl', 'postgresql', 'postgres' ] diff --git a/tasks/postgresql-packages.yml b/tasks/postgresql-packages.yml new file mode 100644 index 0000000..af4d00a --- /dev/null +++ b/tasks/postgresql-packages.yml @@ -0,0 +1,86 @@ +--- +- name: postgresql-packages | Manage the postgresql packages installation + when: + - ansible_distribution_file_variety == "Debian" + - not postgresql_client_only + tags: ['postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql server packages on Deb systems + ansible.builtin.apt: + pkg: "{{ postgresql_pkgs }}" + state: present + cache_valid_time: 3600 + notify: Restart postgresql + +- name: postgresql-packages | Manage the postgresql client installation + when: + - ansible_distribution_file_variety == "Debian" + - postgresql_client_only + tags: ['postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql server packages on Deb systems + ansible.builtin.apt: + pkg: postgresql-client + state: present + cache_valid_time: 3600 + +- name: postgresql-packages | EL server packages + when: + - not psql_el_install_scl_version + - not postgresql_client_only + - ansible_distribution_file_variety == "RedHat" + tags: ['postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql packages from the pgdg repository + ansible.builtin.yum: + pkg: "{{ psql_el_pgdg_packages }}" + state: present + + - name: postgresql-packages | Init the db if needed + ansible.builtin.command: /usr/pgsql-{{ psql_version }}/bin/postgresql-{{ psql_version }}-setup initdb + args: + creates: '{{ psql_el_data_dir }}/postgresql.conf' + +- name: postgresql-packages | EL server packagesx from SCL + when: + - psql_el_install_scl_version + - ansible_distribution_file_variety == "RedHat" + - not postgresql_client_only + tags: ['scl', 'postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql scl packages + ansible.builtin.yum: + pkg: "{{ psql_el_scl_packages }}" + state: present + + - name: postgresql-packages | Init the db if needed + ansible.builtin.command: /opt/rh/rh-postgresql{{ psql_version }}/root/usr/bin/postgresql-setup --initdb + args: + creates: '{{ psql_el_data_dir }}/postgresql.conf' + +- name: postgresql-packages | EL client packages + when: + - not psql_el_install_scl_version + - postgresql_client_only + - ansible_distribution_file_variety == "RedHat" + tags: ['postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql client from the pgdg repository + ansible.builtin.yum: + pkg: "postgresql{{ psql_version }}" + state: present + +- name: postgresql-packages | EL server packagesx from SCL + when: + - psql_el_install_scl_version + - ansible_distribution_file_variety == "RedHat" + - postgresql_client_only + tags: ['scl', 'postgresql', 'postgres'] + block: + - name: postgresql-packages | Install the postgresql scl client package + ansible.builtin.yum: + pkg: "{{ item }}" + state: present + loop: + - "rh-postgresql{{ psql_version }}-runtime" + - "rh-postgresql{{ psql_version }}-postgresql"