Puppet Plan: patching::set_facts
- Defined in:
- plans/set_facts.pp
Summary
Sets patching facts on targetsOverview
For Linux targets the facts will be written to /etc/facter/facts.d/patching.yaml
. For Windows targets the facts will be written to 'C:/ProgramData/PuppetLabs/facter/facts.d/patching.yaml'
.
The contents of the patching.yaml
file will be overwritten by this plan. TODO: Provide an option to merge with existing facts.
Once the facts are written, by default, the facts will be ran and uploaded to PuppetDB. If you wish to disable this, simply set upload=false
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 76 |
# File 'plans/set_facts.pp', line 36
plan patching::set_facts (
TargetSpec $targets,
Optional[String] $patching_group = undef,
Hash $custom_facts = {},
Boolean $upload = true,
) {
# this will set all of the facts on the targets if they have Puppet or not
$_targets = run_plan('patching::get_targets', $targets)
# split by linux vs windows because of the different paths for custom facts
$targets_linux = $_targets.filter |$t| { facts($t)['os']['family'] != 'windows' }
$targets_windows = $_targets.filter |$t| { facts($t)['os']['family'] == 'windows' }
# merge our facts
# the explicitly defined facts always win
$_facts = $custom_facts + {'patching_group' => $patching_group}
$_facts_yaml = to_yaml($_facts)
out::message('============= writing facts.d/patching.yaml =============')
out::message($_facts_yaml)
if !$targets_linux.empty() {
write_file($_facts_yaml,
'/etc/facter/facts.d/patching.yaml',
$targets_linux)
$results_linux = run_command('/opt/puppetlabs/bin/puppet facts upload', $targets_linux)
}
else {
$results_linux = ResultSet([])
}
if !$targets_windows.empty() {
write_file($_facts_yaml,
'C:/ProgramData/PuppetLabs/facter/facts.d/patching.yaml',
$targets_windows)
$results_windows = run_command("& 'C:/Program Files/Puppet Labs/Puppet/bin/puppet' facts upload", $targets_windows)
}
else {
$results_windows = ResultSet([])
}
return ResultSet($results_linux.results + $results_windows.results)
}
|