fix: enable new consul clusters to be started
- wait for the enc_role fact to be correct, as this is required to find all keys in hiera
This commit is contained in:
parent
89fcfe38ea
commit
b6d3fc26de
@ -1,10 +1,16 @@
|
||||
# profiles::consul::server
|
||||
class profiles::consul::server (
|
||||
String $gossip_key,
|
||||
String $primary_datacenter,
|
||||
Hash $acl,
|
||||
Hash $ports,
|
||||
Hash $addresses,
|
||||
Variant[
|
||||
Undef,
|
||||
String
|
||||
] $gossip_key = undef,
|
||||
Variant[
|
||||
Undef,
|
||||
String
|
||||
] $primary_datacenter = undef,
|
||||
Hash $acl = {},
|
||||
Hash $ports = {},
|
||||
Hash $addresses = {},
|
||||
Boolean $members_lookup = false,
|
||||
String $members_role = undef,
|
||||
Array $consul_servers = [],
|
||||
@ -39,57 +45,60 @@ class profiles::consul::server (
|
||||
Boolean $disable_update_check = true,
|
||||
) {
|
||||
|
||||
# set a datacentre/cluster name
|
||||
$consul_cluster = "${::facts['country']}-${::facts['region']}"
|
||||
# wait for all attributes to be ready
|
||||
if $facts['enc_role'] == $members_role {
|
||||
# set a datacentre/cluster name
|
||||
$consul_cluster = "${::facts['country']}-${::facts['region']}"
|
||||
|
||||
# if lookup is enabled, find all the hosts in the specified role and create the servers_array
|
||||
if $members_lookup {
|
||||
# if lookup is enabled, find all the hosts in the specified role and create the servers_array
|
||||
if $members_lookup {
|
||||
|
||||
# check that the role is also set
|
||||
unless !($members_role == undef) {
|
||||
fail("members_role must be provided for ${title} when members_lookup is True")
|
||||
# check that the role is also set
|
||||
unless !($members_role == undef) {
|
||||
fail("members_role must be provided for ${title} when members_lookup is True")
|
||||
}
|
||||
|
||||
# if it is, find hosts, sort them so they dont cause changes every run
|
||||
$servers_array = sort(query_nodes("enc_role='${members_role}' and region='${::facts['region']}'", 'networking.fqdn'))
|
||||
|
||||
# else use provided array from params
|
||||
}else{
|
||||
$servers_array = $consul_servers
|
||||
}
|
||||
|
||||
# if it is, find hosts, sort them so they dont cause changes every run
|
||||
$servers_array = sort(query_nodes("enc_role='${members_role}' and region='${::facts['region']}'", 'networking.fqdn'))
|
||||
# if $data_dir starts with /data, ensure the data mount exists
|
||||
if ($data_dir.stdlib::start_with('/data') and $::facts['mountpoints']['/data']) or ! $data_dir.stdlib::start_with('/data') {
|
||||
|
||||
# else use provided array from params
|
||||
}else{
|
||||
$servers_array = $consul_servers
|
||||
}
|
||||
|
||||
# if $data_dir starts with /data, ensure the data mount exists
|
||||
if ($data_dir.stdlib::start_with('/data') and $::facts['mountpoints']['/data']) or ! $data_dir.stdlib::start_with('/data') {
|
||||
|
||||
# install consul
|
||||
class { 'consul':
|
||||
install_method => $install_method,
|
||||
manage_repo => $manage_repo,
|
||||
package_name => $package_name,
|
||||
package_ensure => $package_ensure,
|
||||
bin_dir => $bin_dir,
|
||||
config_hash => {
|
||||
'primary_datacenter' => $primary_datacenter,
|
||||
'acl' => $acl,
|
||||
'ports' => $ports,
|
||||
'addresses' => $addresses,
|
||||
'disable_remote_exec' => $disable_remote_exec,
|
||||
'disable_update_check' => $disable_update_check,
|
||||
'domain' => $domain,
|
||||
'bootstrap_expect' => $bootstrap_count,
|
||||
'client_addr' => '0.0.0.0',
|
||||
'data_dir' => $data_dir,
|
||||
'datacenter' => $consul_cluster,
|
||||
'log_level' => 'INFO',
|
||||
'node_name' => $::facts['networking']['fqdn'],
|
||||
'server' => true,
|
||||
'ui' => $enable_ui,
|
||||
'ui_config' => { 'enabled' => $enable_ui_config },
|
||||
'performance' => { 'raft_multiplier' => $raft_multiplier },
|
||||
'bind_addr' => $::facts['networking']['ip'],
|
||||
'advertise_addr' => $::facts['networking']['ip'],
|
||||
'retry_join' => $servers_array
|
||||
},
|
||||
# install consul
|
||||
class { 'consul':
|
||||
install_method => $install_method,
|
||||
manage_repo => $manage_repo,
|
||||
package_name => $package_name,
|
||||
package_ensure => $package_ensure,
|
||||
bin_dir => $bin_dir,
|
||||
config_hash => {
|
||||
'primary_datacenter' => $primary_datacenter,
|
||||
'acl' => $acl,
|
||||
'ports' => $ports,
|
||||
'addresses' => $addresses,
|
||||
'disable_remote_exec' => $disable_remote_exec,
|
||||
'disable_update_check' => $disable_update_check,
|
||||
'domain' => $domain,
|
||||
'bootstrap_expect' => $bootstrap_count,
|
||||
'client_addr' => '0.0.0.0',
|
||||
'data_dir' => $data_dir,
|
||||
'datacenter' => $consul_cluster,
|
||||
'log_level' => 'INFO',
|
||||
'node_name' => $::facts['networking']['fqdn'],
|
||||
'server' => true,
|
||||
'ui' => $enable_ui,
|
||||
'ui_config' => { 'enabled' => $enable_ui_config },
|
||||
'performance' => { 'raft_multiplier' => $raft_multiplier },
|
||||
'bind_addr' => $::facts['networking']['ip'],
|
||||
'advertise_addr' => $::facts['networking']['ip'],
|
||||
'retry_join' => $servers_array
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user