Puppet Class: nomad::server_recovery
- Defined in:
- manifests/server_recovery.pp
Overview
This class is used to generate a peers.json and a recovery script file for Nomad servers. It is used to recover from a Nomad server outage.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'manifests/server_recovery.pp', line 30
class nomad::server_recovery (
Optional[String] $network_interface = undef,
Optional[String] $nomad_server_regex = undef,
Optional[Hash] $nomad_server_hash = undef,
Stdlib::Port $rpc_port = 4647,
) {
if ($facts['nomad_node_id']) {
if ($nomad_server_regex) {
$nomad_server_inventory = puppetdb_query(
"inventory[facts.networking.hostname, facts.networking.interfaces.${network_interface}.ip, facts.nomad_node_id] {
facts.networking.hostname ~ '${nomad_server_regex}' and facts.agent_specified_environment = '${facts['agent_specified_environment']}'
}"
)
$nomad_server_pretty_inventory = $nomad_server_inventory.map |$item| {
{
'id' => $item['facts.nomad_node_id'],
'address' => "${item["facts.networking.interfaces.${network_interface}.ip"]}:${rpc_port}",
'non_voter' => false
}
}
} else {
if $nomad_server_hash.keys() !~ Array[Stdlib::IP::Address::Nosubnet] {
fail('The keys of the nomad_server_hash parameter must be valid IP addresses')
}
$nomad_server_pretty_inventory = $nomad_server_hash.map |$key, $value| {
{
'id' => $value,
'address' => "${key}:${rpc_port}",
'non_voter' => false
}
}
}
file {
default:
owner => 'root',
group => 'root';
'/tmp/peers.json':
mode => '0640',
content => to_json_pretty($nomad_server_pretty_inventory);
'/usr/local/bin/nomad-server-outage-recovery.sh':
mode => '0750',
source => 'puppet:///modules/nomad/nomad-server-outage-recovery.sh';
}
}
}
|