diff --git a/roles/setup_pgbouncer/tasks/setup_pgbouncer.yml b/roles/setup_pgbouncer/tasks/setup_pgbouncer.yml index 2efd689dd..8f560f9f2 100644 --- a/roles/setup_pgbouncer/tasks/setup_pgbouncer.yml +++ b/roles/setup_pgbouncer/tasks/setup_pgbouncer.yml @@ -24,11 +24,12 @@ Available authentication types are {{ available_auth_type }}" when: pgbouncer_auth_type not in available_auth_type -- name: Remove pgbouncer install and configuration based on force_pgbouncer +- name: Remove pgbouncer install and configuration based on force_initdb/force_replication/force_pgbouncer ansible.builtin.include_tasks: rm_pgbouncer_install_config.yml - when: - - force_pgbouncer is defined - - force_pgbouncer + when: > + ((force_pgbouncer is defined and force_pgbouncer) or + (force_initdb is defined and force_initdb) or + (force_replication is defined and force_replication)) - name: Include the pgbouncer_install ansible.builtin.include_tasks: pgbouncer_install.yml diff --git a/roles/setup_pgpool2/tasks/rm_pgpool2_install_config.yml b/roles/setup_pgpool2/tasks/rm_pgpool2_install_config.yml new file mode 100644 index 000000000..5b17f186b --- /dev/null +++ b/roles/setup_pgpool2/tasks/rm_pgpool2_install_config.yml @@ -0,0 +1,85 @@ +--- +- name: Gather service facts + ansible.builtin.service_facts: + +- name: Stop pgpool2 service + ansible.builtin.systemd: + name: "{{ pgpool2_service_name }}" + state: stopped + enabled: false + when: + - ansible_facts.services[pgpool2_service_name + '.service'] is defined + - ansible_facts.services[pgpool2_service_name + '.service'].state == 'running' + become: true + +- name: Remove pgpoolII system user {{ pgpool2_user }} + ansible.builtin.user: + name: "{{ pgpool2_user }}" + group: "{{ pgpool2_group }}" + state: absent + remove: true + force: true + become: true + +- name: Remove pgpoolII system group {{ pgpool2_group }} + ansible.builtin.group: + name: "{{ pgpool2_group }}" + state: absent + become: true + +- name: Remove pgpoolII files and directory + ansible.builtin.file: + path: "{{ item }}" + state: absent + loop: + - "{{ pgpool2_configuration_file | dirname }}" + - "{{ pgpool2_logdir }}" + - "{{ pgpool2_systemd_config_file | dirname }}" + - "{{ pgpool2_pid_file_name | dirname }}" + become: true + +- name: Remove optional pgpoolII directory + ansible.builtin.file: + path: "{{ pgpool2_logdir }}" + state: absent + when: pgpool2_logdir is defined + +- name: Remove optional pgpoolII directory + ansible.builtin.file: + path: "{{ pgpool2_pid_file_name | dirname }}" + state: absent + when: pgpool2_pid_file_name is defined + +- name: Remove pgpoolII package + ansible.builtin.package: + name: "{{ pgpool2_package_name }}" + state: absent + become: true + +- name: Remove openssl package + ansible.builtin.package: + name: "openssl" + state: absent + when: + - pgpool2_ssl + become: true + +- name: Remove pgpool-II-pcp package on RedHat + ansible.builtin.package: + name: "pgpool-II-pcp" + state: absent + when: + - ansible_os_family == 'RedHat' + - pg_type == 'PG' + become: true + +- name: Remove dependent packages on Debian + ansible.builtin.package: + name: + - libpgpool2 + - postgresql-client-common + state: absent + when: + - ansible_os_family == 'Debian' + - pg_type == 'PG' + become: true diff --git a/roles/setup_pgpool2/tasks/setup_pgpool2.yml b/roles/setup_pgpool2/tasks/setup_pgpool2.yml index 238527089..8b760719d 100644 --- a/roles/setup_pgpool2/tasks/setup_pgpool2.yml +++ b/roles/setup_pgpool2/tasks/setup_pgpool2.yml @@ -126,6 +126,12 @@ when: - use_hostname|bool +- name: Remove pgpool2 install and configuration based on force_pgpool2 + ansible.builtin.include_tasks: rm_pgpool2_install_config.yml + when: + - force_pgpool2 is defined + - force_pgpool2 + - name: Include the pgpool2_install ansible.builtin.include_tasks: pgpool2_install.yml