Skip to content

Instantly share code, notes, and snippets.

@tspeigner
Created March 17, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tspeigner/755f1b61c780713fbbd185ce1cb03f20 to your computer and use it in GitHub Desktop.
Save tspeigner/755f1b61c780713fbbd185ce1cb03f20 to your computer and use it in GitHub Desktop.
plan os_patching::patch_node(
TargetSpec $target,
Boolean $downtime_enable = true,
){
## Prevalidation task (
$pre_validate = run_script('os_patching/patch.sh', $target,
'arguments' => ['-V'],
_catch_errors => true)
if $pre_validate.ok() {
## update DB with error msg
### No errors from patch validation resultset then no patchingf needed
## NO patching on node
return("Pre_validation successful: no patching needed")
} else {
##Update status in BD to inprogress
## Continue patching .....
out::message("Continue patching .....")
}
if $downtime_enable{
$downtime_result = run_task('os_patching::schedule_downtime', $target,
hostname => $target,
_catch_errors => true)
if $downtime_result.ok() {
out::message("Downtime set on node")
}else{
out::message($downtime_result[0].message)
fail_plan("Count not get downtime for thing")
}
}
#error handling
out::message("Starting Patching Script")
$patch_result = run_script('os_patching/patch.sh', $target,
'arguments' => ['-j'],
_catch_errors => true)
if $patch_result.ok() {
out::message($patch_result.to_data[0]['result']['stdout'])
} else {
out::message($patch_result.to_data[0]['result']['stdout'])
fail_plan("The patching script failed to work fine")
}
#error handling
$last_reboot = run_task('reboot::last_boot_time', $target)
out::message($last_reboot[0].message)
#error handling
$reboot_result = run_task('reboot', $target, message => 'rebooting due to patching')
out::message("Reboot Issued")
#error handling
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment