Puppet Class: patching_as_code::high_prio_reboot

Defined in:
manifests/high_prio_reboot.pp

Summary

This class gets called by init.pp to reboot the node. You can use Hiera to set a different default for the reboot_delay if desired.

Overview

Class: patching_as_code::high_prio_reboot

Parameters:

  • reboot_if_needed (Boolean) (defaults to: true)

    Only reboot the node if a system reboot is pending. This parameter is passed automatically from init.pp

  • reboot_delay (Integer) (defaults to: 120)

    Time in seconds to delay the reboot by, defaults to 2 minutes. To override for patching, specify an alternate value by setting the patching_as_code::high_prio_reboot::reboot_delay parameter in Hiera.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'manifests/high_prio_reboot.pp', line 10

class patching_as_code::high_prio_reboot (
  Boolean $reboot_if_needed = true,
  Integer $reboot_delay = 120
) {
  $reboot_delay_min = round($reboot_delay / 60)
  if $reboot_if_needed {
    # Define an Exec to perform the reboot shortly after the Puppet run completes
    case $facts['kernel'].downcase() {
      'windows': {
        $reboot_logic_provider = 'powershell'
        $reboot_logic_cmd      = "& shutdown /r /t ${reboot_delay} /c \"Patching_as_code: Rebooting system due to a pending reboot after patching\" /d p:2:17" # lint:ignore:140chars 
        $reboot_logic_onlyif   = "${facts['puppet_vardir']}/lib/patching_as_code/pending_reboot.ps1"
      }
      'linux': {
        $reboot_logic_provider = 'posix'
        $reboot_logic_cmd      = "/sbin/shutdown -r +${reboot_delay_min}"
        $reboot_logic_onlyif   = "/bin/sh ${facts['puppet_vardir']}/lib/patching_as_code/pending_reboot.sh"
      }
      default: {
        fail('Unsupported operating system for Patching as Code!')
      }
    }
    exec { 'Patching as Code - High Priority Patch Reboot':
      command   => $reboot_logic_cmd,
      onlyif    => $reboot_logic_onlyif,
      provider  => $reboot_logic_provider,
      logoutput => true,
      schedule  => 'Patching as Code - High Priority Patch Window',
    }
  } else {
    # Reboot as part of this Puppet run
    reboot { 'Patching as Code - High Priority Patch Reboot':
      apply    => 'immediately',
      schedule => 'Patching as Code - High Priority Patch Window',
      timeout  => $reboot_delay,
    }
    notify { 'Patching as Code - Performing OS reboot (High Priority)':
      notify   => Reboot['Patching as Code - High Priority Patch Reboot'],
      schedule => 'Patching as Code - High Priority Patch Window',
    }
  }
}