Puppet Plan: patching::check_puppet
- Defined in:
- plans/check_puppet.pp
Summary
Checks each node to see if Puppet is installed, then gather Facts on all targets.Overview
Executes the puppet_agent::version
task to check if Puppet is installed on all of the targets. Once finished, the result is split into two groups:
1. Targets with puppet
2. Targets with no puppet
The targets with puppet are queried for facts using the patching::puppet_facts
plan. Targets without puppet are queried for facts using the simpler facts
plan.
This plan is designed to be the first plan executed in a patching workflow. It can be used to stop the patching process if any hosts are offline by setting filter_offline_targets=false
(default). It can also be used to patch any hosts that are currently available and ignoring any offline targets by setting filter_offline_targets=true
.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'plans/check_puppet.pp', line 52
plan patching::check_puppet (
TargetSpec $targets,
Boolean $filter_offline_targets = false,
) {
$_targets = get_targets($targets)
## This will check all targets to verify online by checking their Puppet agent version
$targets_version = run_task('puppet_agent::version', $_targets,
_catch_errors => $filter_offline_targets)
# if we're filtering out offline targets, then only accept the ok_set from the task above
if $filter_offline_targets {
$targets_filtered = $targets_version.ok_set
}
else {
$targets_filtered = $targets_version
}
# targets without puppet will return a value {'verison' => undef}
$targets_with_puppet = $targets_filtered.filter_set |$res| { $res['version'] != undef }.targets
$targets_no_puppet = $targets_filtered.filter_set |$res| { $res['version'] == undef }.targets
## get facts from each node
if !$targets_with_puppet.empty() {
# run `puppet facts` on targets with Puppet because it returns a more complete
# set of facts than just running `facter`
run_plan('patching::puppet_facts', $targets_with_puppet)
}
if !$targets_no_puppet.empty() {
# run `facter` if it's available otherwise get basic facts
run_plan('facts', $targets_no_puppet)
}
return({
'has_puppet' => $targets_with_puppet,
'no_puppet' => $targets_no_puppet,
'all' => $targets_with_puppet + $targets_no_puppet,
})
}
|