Skip to content

Commit 9474c8e

Browse files
committed
Refactor Consul bootstrap variable handling
Removed redundant and manual settings of consul_bootstrap_expect in inventory, molecule, and playbooks. Now, consul_bootstrap_expect is automatically set based on consul_node_role in common defaults. Updated cloud_resources to set consul_node_role per host and adjusted datacenter assignment to use server_location. This simplifies Consul configuration and improves consistency.
1 parent c21cba2 commit 9474c8e

File tree

7 files changed

+7
-15
lines changed

7 files changed

+7
-15
lines changed

automation/inventory.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
# if dcs_exists: false and dcs_type: "consul"
1818
[consul_instances] # recommendation: 3 or 5-7 nodes
19-
#10.128.64.140 consul_node_role=server consul_bootstrap_expect=true consul_datacenter=dc1
20-
#10.128.64.142 consul_node_role=server consul_bootstrap_expect=true consul_datacenter=dc1
21-
#10.128.64.143 consul_node_role=server consul_bootstrap_expect=true consul_datacenter=dc1
19+
#10.128.64.140 consul_node_role=server consul_datacenter=dc1
20+
#10.128.64.142 consul_node_role=server consul_datacenter=dc1
21+
#10.128.64.143 consul_node_role=server consul_datacenter=dc1
2222
#10.128.64.144 consul_node_role=client consul_datacenter=dc2
2323
#10.128.64.145 consul_node_role=client consul_datacenter=dc2
2424

automation/molecule/default/converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
dcs_type: "{{ 'etcd' if ansible_distribution_major_version in ['10'] or ansible_distribution_release in ['trixie']
1818
else (['etcd', 'consul'] | random) }}" # TODO: Consul support for RHEL 10, Debian 13
1919
consul_node_role: server # if dcs_type: "consul"
20-
consul_bootstrap_expect: true # if dcs_type: "consul"
2120
postgresql_version: 18
2221
pgbouncer_processes: 2 # Test multiple pgbouncer processes (so_reuseport)
2322
patroni_tags: "datacenter=dc1,key1=value1"

automation/molecule/pg_upgrade/converge.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
dcs_type: "{{ 'etcd' if ansible_distribution_major_version in ['10'] or ansible_distribution_release in ['trixie']
1818
else (['etcd', 'consul'] | random) }}" # TODO: Consul support for RHEL 10, Debian 13
1919
consul_node_role: server # if dcs_type: "consul"
20-
consul_bootstrap_expect: true # if dcs_type: "consul"
2120
postgresql_version: 17 # redefine the version to install for the upgrade test
2221
pgbouncer_processes: 4 # Test multiple pgbouncer processes (so_reuseport)
2322
cacheable: true

automation/playbooks/consul_cluster.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@
148148
consul_dnsmasq_servers: "{{ consul_dnsmasq_servers | reject('equalto', '127.0.0.1') | list }}"
149149
when: dcs_type | default('etcd') == "consul" and consul_dnsmasq_enable | default(true) | bool and ('127.0.0.1' in (consul_dnsmasq_servers | default([])))
150150

151-
# Setting variables for Consul during cloud deployment
152-
- name: Redefine the consul_node_role and consul_bootstrap_expect variables
153-
ansible.builtin.set_fact:
154-
consul_node_role: "{{ 'server' if not dcs_exists | default(false) else 'client' }}"
155-
consul_bootstrap_expect: "{{ not dcs_exists | default(false) }}"
156-
consul_datacenter: "{{ server_location | default('dc1') }}"
157-
when: cloud_provider | default('') | length > 0
158-
159151
roles:
160152
- role: vitabaks.autobase.firewall
161153
vars:

automation/roles/cloud_resources/tasks/inventory.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
ansible.builtin.add_host:
7979
name: "{{ item.private_ip }}"
8080
group: consul_instances
81+
consul_node_role: "{{ 'server' if not dcs_exists | default(false) else 'client' }}"
8182
ansible_ssh_host: "{{ item[server_public_ip | bool | ternary('public_ip', 'private_ip')] }}"
8283
ansible_ssh_private_key_file: "{{ ssh_private_key_file | default(None) }}"
8384
new_node: "{{ item.new_node | default(omit) }}"

automation/roles/common/defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ consul_config_path: "/etc/consul"
156156
consul_configd_path: "{{ consul_config_path }}/conf.d"
157157
consul_data_path: "/var/lib/consul"
158158
consul_domain: "consul" # Consul domain name
159-
consul_datacenter: "dc1" # Datacenter label (can be specified for each host in the inventory)
159+
consul_datacenter: "{{ server_location | default('dc1') }}" # Datacenter label (can be specified for each host in the inventory)
160160
consul_disable_update_check: true # Disables automatic checking for security bulletins and new version releases
161161
consul_enable_script_checks: true # This controls whether health checks that execute scripts are enabled on this agent
162162
consul_enable_local_script_checks: true # Enable them when they are defined in the local configuration files
163163
consul_ui: false # Enable the consul UI?
164164
consul_syslog_enable: true # Enable logging to syslog
165165
consul_client_address: "127.0.0.1" # Client address. Affects DNS, HTTP, HTTPS, and gRPC client interfaces.
166+
consul_bootstrap_expect: "{{ true if consul_node_role == 'server' else false }}"
166167
consul_on_dedicated_nodes: "{{ groups['consul_instances'] | difference(groups['postgres_cluster']) | length > 0 }}" # 'true' or 'false'
167168
# TLS
168169
# Enables TLS encryption with a self-signed certificate if 'tls_cert_generate' is true.

automation/roles/consul/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ consul_alt_domain: "{{ lookup('env', 'CONSUL_ALT_DOMAIN') | default('', true) }}
8383
consul_node_meta: {}
8484
consul_node_role: "{{ lookup('env', 'CONSUL_NODE_ROLE') | default('client', true) }}"
8585
# consul_recursors: "{{ lookup('env', 'CONSUL_RECURSORS') | default('[]', true) }}"
86-
consul_bootstrap_expect: "{{ lookup('env', 'CONSUL_BOOTSTRAP_EXPECT') | default(false, true) }}"
86+
# consul_bootstrap_expect: "{{ lookup('env', 'CONSUL_BOOTSTRAP_EXPECT') | default(false, true) }}"
8787
consul_bootstrap_expect_value: "{{ _consul_lan_servercount | int }}"
8888
# consul_ui: "{{ lookup('env', 'CONSUL_UI') | default(true, true) }}"
8989
consul_ui_legacy: "{{ lookup('env', 'CONSUL_UI_LEGACY') | default(false, false) }}"

0 commit comments

Comments
 (0)