476c8115c5
Replace deprecated dalen-puppetdbquery module with native puppetdb_query function using PQL syntax to resolve URI.escape compatibility issues. This is required to migrated to Puppet 8 (and kubernetes). Changes: - Remove dalen-puppetdbquery dependency from Puppetfile - Replace query_nodes() calls with puppetdb_query() using PQL syntax - Update 27 function calls across 18 Puppet manifests - Maintain equivalent functionality with improved compatibility Reviewed-on: #457
64 lines
2.2 KiB
Puppet
64 lines
2.2 KiB
Puppet
# manage the use of the etcd module
|
|
class profiles::etcd::node (
|
|
Sensitive[String[1]] $initial_cluster_token,
|
|
Boolean $members_lookup = false,
|
|
String $members_role = undef,
|
|
Array $servers = [],
|
|
Stdlib::Port $client_port = 2379,
|
|
Stdlib::Port $peer_port = 2380,
|
|
Hash $config = {},
|
|
){
|
|
|
|
# if lookup is enabled
|
|
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")
|
|
}
|
|
|
|
# if it is, find hosts, sort them so they dont cause changes every run
|
|
$servers_array = sort(puppetdb_query(
|
|
"facts[certname] {
|
|
name = 'enc_role' and value = '${members_role}' and
|
|
certname in facts[certname] { name = 'region' and value = '${facts['region']}' }
|
|
}"
|
|
).map |$fact| { $fact['certname'] })
|
|
|
|
# else use provided array from params
|
|
}else{
|
|
$servers_array = sort($servers)
|
|
}
|
|
|
|
if length($servers_array) >= 3 {
|
|
|
|
# construct the initial-cluster string
|
|
$initial_cluster = $servers_array.map |$fqdn| {
|
|
|
|
# lookup the ip address for the current fqdn
|
|
$ip = puppetdb_query("facts[certname,value] { name = 'networking' and certname = '${fqdn}' }").map |$fact| { $fact['value']['ip'] }[0]
|
|
|
|
# construct the string for this server
|
|
"${fqdn}=https://${ip}:${peer_port}"
|
|
}.join(',')
|
|
|
|
$defaults = {
|
|
'data-dir' => '/var/lib/etcd',
|
|
'name' => $facts['networking']['fqdn'],
|
|
'listen-client-urls' => "https://${facts['networking']['ip']}:${client_port}",
|
|
'listen-peer-urls' => "https://${facts['networking']['ip']}:${peer_port}",
|
|
'advertise-client-urls' => "https://${facts['networking']['ip']}:${client_port}",
|
|
'initial-advertise-peer-urls' => "https://${facts['networking']['ip']}:${peer_port}",
|
|
'initial-cluster-token' => $initial_cluster_token.unwrap,
|
|
'initial-cluster' => $initial_cluster,
|
|
'initial-cluster-state' => 'new',
|
|
}
|
|
|
|
$merged_config = merge($defaults, $config)
|
|
|
|
class { 'etcd':
|
|
config => $merged_config,
|
|
}
|
|
}
|
|
}
|