feat: add etcd module/role (#215)
- add etcd module - add etcd role, profile and hieradata Reviewed-on: https://git.query.consul/unkinben/puppet-prod/pulls/215
This commit was merged in pull request #215.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# 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(query_nodes("enc_role='${members_role}' and region='${facts['region']}'", 'networking.fqdn'))
|
||||
|
||||
# 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 = query_nodes("networking.fqdn='${fqdn}'", 'networking.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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user