Puppet Class: psick::firstrun
- Defined in:
- manifests/firstrun.pp
Summary
Special class applied only at first Puppet runOverview
This special class is supposed to be included ONLY at the first Puppet run. It’s up to user to decide if to enable it (by setting psick::enable_firstrun) and it’s up to the user to decide what classes to include in this run and if to trigger a system reboot after this Puppet run.
By default, if psick::enable_firstrun is set to true, this class automatically includes the classes listed in the $kernel_classes hashes, triggers a reboot (on Windows) and creates an external fact that prevents a reboot cycle. IMPORTANT NOTE: If firstrun mode is activated on an existing infrastructure or if the ‘firstrun’ external fact is removed from nodes, this class will included in the main psick class as if this were a real first Puppet run. This will trigger a, probably unwanted, reboot on Windows nodes (and in any other node for which reboot is configured. Set psick::firstrun::$kernel_reboot to false to prevent undesired reboots.
Use cases:
-
Set a desired hostname on Windows, reboot and join an AD domain
-
Install aws-sdk gem, reboot and have ec2_tags facts since the first real Puppet run
-
Set external facts with configurable content (not via pluginsync) and run a catalog only when they are loaded (after the first Puppet run)
-
Any case where a configuration or some installations have to be done in a separated and never repeating first Puppet run. With or without a system reboot
on Linux but do not trigger any reboot
psick::enable_firstrun: true
psick::firstrun::linux_classes:
hostname: psick::hostname
proxy: psick::proxy
psick::firstrun::linux_reboot: false # (Default value)
For each of these $facts_classes parameters, it’s expected an Hash of key-values: Keys can have any name, and are used as markers to allow overrides, exceptions management and customisations across Hiera’s hierarchies. Values are actual class names to include in the node’s catalog only at first Puppet execution. They can be classes from psick module or any other module.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'manifests/firstrun.pp', line 86
class psick::firstrun (
Psick::Class $linux_classes = {},
Psick::Class $windows_classes = {},
Psick::Class $darwin_classes = {},
Psick::Class $solaris_classes = {},
Boolean $linux_reboot = false,
Boolean $windows_reboot = true,
Boolean $darwin_reboot = false,
Boolean $solaris_reboot = false,
Enum['immediately','finished'] $reboot_apply = 'finished',
Enum['refreshed','pending'] $reboot_when = 'refreshed',
String $reboot_message = 'firstboot mode enabled, rebooting after first Puppet run',
String $reboot_name = 'Rebooting',
Integer $reboot_timeout = 60,
Boolean $manage = $psick::manage,
Boolean $noop_manage = $psick::noop_manage,
Boolean $noop_value = $psick::noop_value,
) {
if $manage {
if $noop_manage {
noop($noop_value)
}
if !empty($linux_classes) and $facts['kernel'] == 'Linux' {
$linux_classes.each |$n,$c| {
if $c != '' {
contain $c
Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
}
}
}
if !empty($windows_classes) and $facts['kernel'] == 'windows' {
$windows_classes.each |$n,$c| {
if $c != '' {
contain $c
Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
}
}
}
if !empty($darwin_classes) and $facts['kernel'] == 'Darwin' {
$darwin_classes.each |$n,$c| {
if $c != '' {
contain $c
Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
}
}
}
if !empty($solaris_classes) and $facts['kernel'] == 'Solaris' {
$solaris_classes.each |$n,$c| {
if $c != '' {
contain $c
Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
}
}
}
# Reboot
$kernel_down = downcase($facts['kernel'])
$reboot = getvar("${kernel_down}_reboot")
$fact_notify = $reboot ? {
false => undef,
true => Reboot[$reboot_name],
}
psick::puppet::set_external_fact { 'firstrun':
value => 'done',
notify => $fact_notify,
}
if $reboot {
reboot { $reboot_name:
apply => $reboot_apply,
message => $reboot_message,
when => $reboot_when,
timeout => $reboot_timeout,
}
}
}
}
|