Puppet Function: generate_reboot_msg

Defined in:
lib/puppet/parser/functions/generate_reboot_msg.rb
Function type:
Ruby 3.x API

Overview

generate_reboot_msg()Strin

Generate a reboot message from a passed Hash.

Requires a Hash of the following form:

ruby { 'id' => 'reason', 'id2' => 'reason2', ... }

Will return a message such as:

A system reboot is required due to: id => reason id2 => reason2

Returns:

  • (Strin)

    Strin



2
3
4
5
6
7
8
9
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
# File 'lib/puppet/parser/functions/generate_reboot_msg.rb', line 2

newfunction(:generate_reboot_msg, :type => :rvalue, :doc => <<-ENDHEREDOC) do |input_hash|

  input_hash = input_hash.shift
  Generate a reboot message from a passed `Hash`.

  Requires a `Hash` of the following form:

  ``ruby
  {
    'id'  => 'reason',
    'id2' => 'reason2',
    ...
  }
  ``

  Will return a message such as:

  ``
  A system reboot is required due to:
    id => reason
    id2 => reason2
  ``

  @return [String]
  ENDHEREDOC

  raise(Puppet::ParseError,"Error: input to generate_reboot() must be a Hash, got '#{input_hash.class}'") unless input_hash.is_a?(Hash)
  raise(Puppet::ParseError,"Error: input to generate_reboot() must not be empty") if input_hash.empty?

  msg = ['System Reboot Required Because:']
  input_hash.each_pair do |k,v|
    if (not v or v.empty?) then
      msg << "  #{k}"
    else
      msg << "  #{k} => #{v}"
    end
  end

  msg.join("\n")
end