Puppet Plan: patching::available_updates
- Defined in:
- plans/available_updates.pp
Summary
Checks all targets for available updates reported by their Operating System.Overview
This uses the patching::available_updates
task to query each Target’s Operating System for available updates. The results from the OS are parsed and formatted into easy to consume JSON data, such that further code can be written against the output.
- RHEL: This ultimately performs a <code>yum check-update</code>.
- Ubuntu: This ultimately performs a <code>apt upgrade --simulate</code>.
- Windows:
- Windows Update API: Queries the WUA for updates. This is the standard update mechanism
for Windows.
- Chocolatey: If installed, runs <code>choco outdated</code>.
If not installed, Chocolatey is ignored.
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'plans/available_updates.pp', line 52
plan patching::available_updates (
TargetSpec $targets,
# TODO JSON
Enum['none', 'pretty', 'csv'] $format = 'pretty',
Boolean $noop = false,
Optional[String] $provider = undef,
) {
$available_results = run_task('patching::available_updates', $targets,
provider => $provider,
_noop => $noop)
case $format {
'none': {
return($available_results)
}
'pretty': {
out::message("Host update status: ('+' has available update; '-' no update) [num updates]")
$has_updates = $available_results.filter_set|$res| { !$res['updates'].empty() }.targets
$no_updates = $available_results.filter_set|$res| { $res['updates'].empty() }.targets
$available_results.each|$res| {
$num_updates = $res['updates'].size
$symbol = ($num_updates > 0) ? { true => '+' , default => '-' }
out::message(" ${symbol} ${res.target.name} [${num_updates}]")
}
return({
'has_updates' => $has_updates,
'no_updates' => $no_updates,
})
}
'csv': {
$csv_header = "hostname,num_updates,name,version (linux only),kbs (windows only)\n"
$csv = $available_results.reduce($csv_header) |$res_memo, $res| {
$hostname = $res.target.name
$num_updates = $res['updates'].length
$host_updates = $res['updates'].reduce('') |$up_memo, $up| {
$name = $up['name']
$version = ('version' in $up) ? {
true => $up['version'],
default => '',
}
$kb_ids = ('kb_ids' in $up) ? {
true => $up['kb_ids'].join(','),
default => '',
}
$csv_line = "${hostname},${num_updates},${name},${version},${kb_ids}"
out::message($csv_line)
"${up_memo}${csv_line}\n"
}
"${res_memo}${host_updates}"
}
file::write('available_updates.csv', $csv)
out::message($csv)
return($csv)
}
default: {
fail_plan("unknown format: ${format}")
}
}
}
|