vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on Patroni). Automating with Ansible.
https://postgresql-cluster.org
MIT License
1.69k stars 411 forks source link

Improvement suggestion remove_cluster.yml #449

Closed rrrru closed 1 year ago

rrrru commented 1 year ago

Update

    - name: Stop Consul service
      ansible.builtin.service:
        name: consul
        state: stopped
        enabled: false
      when: remove_consul | bool
    - name: Delete Consul content
      ansible.builtin.file:
        path: "{{ consul_data_path }}"
        state: absent
      when: remove_consul | bool

To:

    - name: Remove KV items from Consul
      ansible.builtin.shell: |
        "consul kv delete -recurse service/{{ patroni_cluster_name }}"
      args:
        executable: /bin/bash
      ignore_errors: true
      when: remove_consul | bool
    - name: Stop Consul service
      ansible.builtin.service:
        name: consul
        state: stopped
        enabled: false
      when: remove_consul | bool
    - name: Delete Consul content
      ansible.builtin.file:
        path: "{{ consul_data_path }}"
        state: absent
      when: remove_consul | bool

Related https://github.com/vitabaks/postgresql_cluster/issues/448#issuecomment-1687024565

vitabaks commented 1 year ago

the task "Remove KV items from Consul" looks superfluous because next comes the task "Delete Consul content" which deletes all Consul data.

rrrru commented 1 year ago

the task "Remove KV items from Consul" looks superfluous because next comes the task "Delete Consul content" which deletes all Consul data.

I know it sounds strange. Yes, but it doesn't work, deleting the directory doesn't delete the data from kv.

Steps to reproduce:

  1. Deploy the cluster using Consul DCS
  2. Remove the cluster remove_cluster.yml -e remove_consul=true
  3. Log on to any consul node, systemctl start consul
  4. consul kv get -recurse
vitabaks commented 1 year ago

Feel free to create a PR

rrrru commented 1 year ago

Removal of keys from KV via Consul API was an incorrect assumption. The problem is the scope of the server for the job (postgres_cluster) I am using a separate server for Consul (consul_instances)