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

Consul: Fix '_consul_lan_servers' variable to resolve 'hostvars[' ']' not defined' #440

Closed vitabaks closed 1 year ago

vitabaks commented 1 year ago

issue https://github.com/vitabaks/postgresql_cluster/issues/437

In this PR, we addressed issues related to the formatting of the consul_servers and _consul_lan_servers variables.

The variable was previously formatted in a way that led to unnecessary line breaks and empty list elements. This caused errors when attempting to access mandatory variables from hostvars.

To fix this, we refactored the variable definition code to ensure that the list is properly formatted without extraneous whitespace, line breaks, or empty elements. This adjustment will enhance the reliability of the variable and prevent issues like the 'Mandatory variable 'hostvars[' ']' not defined' error.

The commit after which the variables were "broken": https://github.com/vitabaks/postgresql_cluster/commit/51f17d663a10c8596a59099eb9e0bc3cc76b2bd6#diff-bfe4d1591b7e700567edc1a7cd12f30615d1bf0ec4e639b789c2e0a0fbcc7eb4

vitabaks commented 1 year ago

FYI @ThomasSanson

The commit after which the variables were "broken": https://github.com/vitabaks/postgresql_cluster/commit/51f17d663a10c8596a59099eb9e0bc3cc76b2bd6#diff-bfe4d1591b7e700567edc1a7cd12f30615d1bf0ec4e639b789c2e0a0fbcc7eb4

this once again shows the need for tests for the Type C scheme

It will be necessary to allocate time and try again to add a scheme with consul to the molecule tests - https://github.com/vitabaks/postgresql_cluster/issues/375

vitabaks commented 1 year ago

Test result: passed

  TASK [deploy-finish : PostgreSQL Cluster health] *******************************
  ok: [10.172.0.20] => {
      "patronictl_result.stdout_lines": [
          "+ Cluster: postgres-cluster -------+-----------+----+-----------+",
          "| Member   | Host        | Role    | State     | TL | Lag in MB |",
          "+----------+-------------+---------+-----------+----+-----------+",
          "| pgnode01 | 10.172.0.20 | Leader  | running   |  2 |           |",
          "| pgnode02 | 10.172.0.21 | Replica | streaming |  2 |         0 |",
          "| pgnode03 | 10.172.0.22 | Replica | streaming |  2 |         0 |",
          "+----------+-------------+---------+-----------+----+-----------+"
      ]
  }

  TASK [deploy-finish : PostgreSQL Cluster connection info] **********************
  ok: [10.172.0.20] => {
      "msg": [
          "+------------------------------------------------+",
          "Client access point (DNS):",
          " master.postgres-cluster.service.consul ",
          " replica.postgres-cluster.service.consul ",
          "port 6432 (pgbouncer)",
          "+------------------------------------------------+"
      ]
  }