From ef819fcdecca540ba6784ce9004ce38107dda20f Mon Sep 17 00:00:00 2001 From: Sergey Lavrinenko Date: Wed, 27 Sep 2023 19:34:33 +0300 Subject: [PATCH 1/5] Patroni pre-checks: check etcd cluster accessible --- add_pgnode.yml | 6 ++++++ config_pgcluster.yml | 1 + deploy_pgcluster.yml | 3 +++ pg_upgrade.yml | 2 ++ roles/patroni/pre-checks/tasks/main.yml | 22 ++++++++++++++++++++++ 5 files changed, 34 insertions(+) create mode 100644 roles/patroni/pre-checks/tasks/main.yml diff --git a/add_pgnode.yml b/add_pgnode.yml index ecbf1dac6..5dff8ccc3 100644 --- a/add_pgnode.yml +++ b/add_pgnode.yml @@ -46,6 +46,12 @@ var: new_nodes tags: always + - name: "Patroni pre-checks" + ansible.builtin.include_role: + name: patroni/pre-checks + when: + - new_node | default(false) | bool + - name: Add a new node to pg_hba.conf on existing cluster nodes ansible.builtin.include_role: name: patroni/config diff --git a/config_pgcluster.yml b/config_pgcluster.yml index 4683f3f2a..a630aebaa 100644 --- a/config_pgcluster.yml +++ b/config_pgcluster.yml @@ -63,6 +63,7 @@ vars: minimal_ansible_version: 2.11.0 timescale_minimal_pg_version: 12 # if enable_timescale is defined + - role: patroni/pre-checks tags: - always diff --git a/deploy_pgcluster.yml b/deploy_pgcluster.yml index eef011a98..2dfa9a031 100644 --- a/deploy_pgcluster.yml +++ b/deploy_pgcluster.yml @@ -50,6 +50,9 @@ timescale_minimal_pg_version: 12 # if enable_timescale is defined tags: always + - role: patroni/pre-checks + tags: always + tasks: - name: Clean yum cache ansible.builtin.command: yum clean all diff --git a/pg_upgrade.yml b/pg_upgrade.yml index 1de434d0c..f0423e232 100644 --- a/pg_upgrade.yml +++ b/pg_upgrade.yml @@ -70,6 +70,8 @@ ansible.builtin.include_role: name: upgrade tasks_from: pre_checks + - ansible.builtin.include_role: + name: patroni/pre-checks tags: - upgrade - pre-checks diff --git a/roles/patroni/pre-checks/tasks/main.yml b/roles/patroni/pre-checks/tasks/main.yml new file mode 100644 index 000000000..282f2307c --- /dev/null +++ b/roles/patroni/pre-checks/tasks/main.yml @@ -0,0 +1,22 @@ +- block: + - name: "Check all hosts of the etcd cluster" + wait_for: + host: "{{ item.host }}" + port: "{{ item.port }}" + state: started + delay: 0 + timeout: 2 + register: patroni_precheck_etcd_port_results + loop: "{{ patroni_etcd_hosts }}" + ignore_errors: true + + - name: "Check if etcd cluster accessible" + run_once: true # noqa run-once + ansible.builtin.fail: + msg: "Please make sure that the etcd cluster nodes are accessible from '{{ inventory_hostname }}'" + when: + - patroni_precheck_etcd_port_results['results'] | rejectattr('failed') | length < 1 + + # TODO: check etcd v3 auth (need gRPC tool) + + when: dcs_exists|bool and dcs_type == 'etcd' From a8943d8db6e51129977c45e9b3279fb2351205cb Mon Sep 17 00:00:00 2001 From: Sergey Lavrinenko Date: Wed, 27 Sep 2023 19:48:17 +0300 Subject: [PATCH 2/5] Do patroni pre-checks only on deploy new hosts --- config_pgcluster.yml | 1 - pg_upgrade.yml | 2 -- 2 files changed, 3 deletions(-) diff --git a/config_pgcluster.yml b/config_pgcluster.yml index a630aebaa..4683f3f2a 100644 --- a/config_pgcluster.yml +++ b/config_pgcluster.yml @@ -63,7 +63,6 @@ vars: minimal_ansible_version: 2.11.0 timescale_minimal_pg_version: 12 # if enable_timescale is defined - - role: patroni/pre-checks tags: - always diff --git a/pg_upgrade.yml b/pg_upgrade.yml index f0423e232..1de434d0c 100644 --- a/pg_upgrade.yml +++ b/pg_upgrade.yml @@ -70,8 +70,6 @@ ansible.builtin.include_role: name: upgrade tasks_from: pre_checks - - ansible.builtin.include_role: - name: patroni/pre-checks tags: - upgrade - pre-checks From 42e69bd62324624052ce7cc3e7384bd3a9dca629 Mon Sep 17 00:00:00 2001 From: Sergey Lavrinenko Date: Wed, 27 Sep 2023 20:02:25 +0300 Subject: [PATCH 3/5] linter fix --- roles/patroni/pre-checks/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/patroni/pre-checks/tasks/main.yml b/roles/patroni/pre-checks/tasks/main.yml index 282f2307c..370952692 100644 --- a/roles/patroni/pre-checks/tasks/main.yml +++ b/roles/patroni/pre-checks/tasks/main.yml @@ -1,6 +1,6 @@ - block: - name: "Check all hosts of the etcd cluster" - wait_for: + ansible.builtin.wait_for: host: "{{ item.host }}" port: "{{ item.port }}" state: started From e84509f21825fe5fd5dc30c181ed4bbdb9f602d0 Mon Sep 17 00:00:00 2001 From: Sergey Lavrinenko Date: Wed, 27 Sep 2023 20:12:37 +0300 Subject: [PATCH 4/5] linter fix again --- roles/patroni/pre-checks/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/patroni/pre-checks/tasks/main.yml b/roles/patroni/pre-checks/tasks/main.yml index 370952692..222a30d54 100644 --- a/roles/patroni/pre-checks/tasks/main.yml +++ b/roles/patroni/pre-checks/tasks/main.yml @@ -15,7 +15,7 @@ ansible.builtin.fail: msg: "Please make sure that the etcd cluster nodes are accessible from '{{ inventory_hostname }}'" when: - - patroni_precheck_etcd_port_results['results'] | rejectattr('failed') | length < 1 + - patroni_precheck_etcd_port_results['results'] | rejectattr('failed') | length < 1 # TODO: check etcd v3 auth (need gRPC tool) From d401e69aa8e2d537ecd0a4acaef783cd268a0211 Mon Sep 17 00:00:00 2001 From: Sergey Lavrinenko Date: Wed, 27 Sep 2023 20:40:06 +0300 Subject: [PATCH 5/5] linter one more time --- roles/patroni/pre-checks/tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/patroni/pre-checks/tasks/main.yml b/roles/patroni/pre-checks/tasks/main.yml index 222a30d54..7f50bedea 100644 --- a/roles/patroni/pre-checks/tasks/main.yml +++ b/roles/patroni/pre-checks/tasks/main.yml @@ -1,3 +1,4 @@ +--- - block: - name: "Check all hosts of the etcd cluster" ansible.builtin.wait_for: