diff --git a/ansible/inventory/offline/99-static b/ansible/inventory/offline/99-static index f6e469574..e6cfb55ce 100644 --- a/ansible/inventory/offline/99-static +++ b/ansible/inventory/offline/99-static @@ -83,19 +83,6 @@ [postgresql:vars] postgresql_network_interface = enp1s0 -repmgr_node_config: - postgresql1: # Maps to postgresql_rw group - node_id: 1 - priority: 150 - role: primary - postgresql2: # Maps to first postgresql_ro - node_id: 2 - priority: 100 - role: standby - postgresql3: # Maps to second postgresql_ro - node_id: 3 - priority: 50 - role: standby [elasticsearch:vars] # elasticsearch_network_interface = enp1s0 @@ -110,8 +97,10 @@ repmgr_node_config: # Rabbitmq specific variables [rmq-cluster:vars] -# host name here must match each node's actual hostname -rabbitmq_cluster_master: rabbitmq1 +# host name here must match each node's actual hostname (short hostname, not FQDN) +# e.g. if the node's FQDN is rabbitmq1.example.com, use: rabbitmq_cluster_master = rabbitmq1 +# Using FQDN here will cause rabbitmqctl join_cluster to fail with a :badarg error +# rabbitmq_cluster_master = rabbitmq1 # rabbitmq_network_interface = enp1s0 # For the following groups, add all nodes defined above to the sections below. diff --git a/ansible/inventory/offline/group_vars/postgresql/postgresql.yml b/ansible/inventory/offline/group_vars/postgresql/postgresql.yml index 351b99539..b427440d0 100644 --- a/ansible/inventory/offline/group_vars/postgresql/postgresql.yml +++ b/ansible/inventory/offline/group_vars/postgresql/postgresql.yml @@ -23,9 +23,6 @@ repmgr_namespace: "{{ wire_namespace | default('default') }}" # This is managed alongside repmgr credentials in postgresql-secrets.yml wire_pg_secret_name: "wire-postgresql-external-secret" -# Node configuration for repmgr -# NOTE: repmgr_node_config is defined in the inventory file ansible/inventory/offline/99-static, ansible/inventory/offline/staging.yml and terraform/examples/wire-server-deploy-offline-hetzner/outputs.tf -# to allow environment-specific node mappings. Do not define here. # repmgr settings # repmgrd monitoring and reconnection configuration diff --git a/ansible/templates/postgresql/repmgr.conf.j2 b/ansible/templates/postgresql/repmgr.conf.j2 index bad9b5a17..3e02b7551 100644 --- a/ansible/templates/postgresql/repmgr.conf.j2 +++ b/ansible/templates/postgresql/repmgr.conf.j2 @@ -5,12 +5,12 @@ # NODE IDENTIFICATION # Ref: https://www.repmgr.org/docs/current/configuration-file.html # ==================================================================== -{% set node_config = repmgr_node_config[inventory_hostname] | default({}) %} -node_id={{ node_config.node_id | default(1) }} +{% set _rw = groups['postgresql_rw'] | default([]) %} +{% set _ro = groups['postgresql_ro'] | default([]) %} +{% set _all_pg = _rw + _ro %} +node_id={{ _all_pg.index(inventory_hostname) + 1 }} node_name='{{ inventory_hostname }}' -{% if node_config.priority is defined %} -priority={{ node_config.priority }} -{% endif %} +priority={{ 150 if inventory_hostname in _rw else ((_ro | length - _ro.index(inventory_hostname)) * 50) }} # ==================================================================== # CONNECTION SETTINGS diff --git a/ansible/templates/postgresql/simple_fence.sh.j2 b/ansible/templates/postgresql/simple_fence.sh.j2 index effc2a1f1..30a226dd9 100644 --- a/ansible/templates/postgresql/simple_fence.sh.j2 +++ b/ansible/templates/postgresql/simple_fence.sh.j2 @@ -8,7 +8,8 @@ PGUSER="{{ repmgr_user }}" PGDATABASE="{{ repmgr_database }}" LOGFILE="/var/log/postgresql/fence_events.log" SCRIPT_NAME="simple_fence" -LOCAL_NODE_ID="{{ repmgr_node_config[inventory_hostname].node_id if repmgr_node_config is defined and repmgr_node_config.get(inventory_hostname) and repmgr_node_config[inventory_hostname].get('node_id') else '1' }}" +{% set _all_pg = groups['postgresql_rw'] | default([]) + groups['postgresql_ro'] | default([]) %} +LOCAL_NODE_ID="{{ _all_pg.index(inventory_hostname) + 1 }}" # Node mappings (id → ip/name), generated from inventory if available declare -A NODE_HOSTS=({% set nodes = ((groups.postgresql_rw|default([])) + (groups.postgresql_ro|default([]))) -%} diff --git a/changelog.d/5-bug-fixes/fix-rabbitmq-repmgr-inventory-syntax b/changelog.d/5-bug-fixes/fix-rabbitmq-repmgr-inventory-syntax new file mode 100644 index 000000000..ccfe20e55 --- /dev/null +++ b/changelog.d/5-bug-fixes/fix-rabbitmq-repmgr-inventory-syntax @@ -0,0 +1 @@ +Fixed: rabbitmq_cluster_master and repmgr_node_config syntax errors in offline inventory 99-static