Puppet Class: psick::firstrun

Defined in:
manifests/firstrun.pp

Summary

Special class applied only at first Puppet run

Overview

This special class is supposed to be included ONLY at the first Puppet run. It’s up to user to decide if to enable it (by setting psick::enable_firstrun) and it’s up to the user to decide what classes to include in this run and if to trigger a system reboot after this Puppet run.

By default, if psick::enable_firstrun is set to true, this class automatically includes the classes listed in the $kernel_classes hashes, triggers a reboot (on Windows) and creates an external fact that prevents a reboot cycle. IMPORTANT NOTE: If firstrun mode is activated on an existing infrastructure or if the ‘firstrun’ external fact is removed from nodes, this class will included in the main psick class as if this were a real first Puppet run. This will trigger a, probably unwanted, reboot on Windows nodes (and in any other node for which reboot is configured. Set psick::firstrun::$kernel_reboot to false to prevent undesired reboots.

Use cases:

  • Set a desired hostname on Windows, reboot and join an AD domain

  • Install aws-sdk gem, reboot and have ec2_tags facts since the first real Puppet run

  • Set external facts with configurable content (not via pluginsync) and run a catalog only when they are loaded (after the first Puppet run)

  • Any case where a configuration or some installations have to be done in a separated and never repeating first Puppet run. With or without a system reboot

on Linux but do not trigger any reboot

psick::enable_firstrun: true
psick::firstrun::linux_classes:
  hostname: psick::hostname
  proxy: psick::proxy
psick::firstrun::linux_reboot: false # (Default value)

For each of these $facts_classes parameters, it’s expected an Hash of key-values: Keys can have any name, and are used as markers to allow overrides, exceptions management and customisations across Hiera’s hierarchies. Values are actual class names to include in the node’s catalog only at first Puppet execution. They can be classes from psick module or any other module.

Examples:

Enable firstrun and configure it to set hostname on Windows and reboot

psick::enable_firstrun: true
psick::firstrun::windows_classes:
  hostname: psick::hostname
psick::firstrun::windows_reboot: true # (Default value)

Enable firstrun and configure it to set hostname and proxy

Disable the whole class (no resource from this class is declared)

psick::firstrun::manage: false

Parameters:

  • linux_classes (Psick::Class) (defaults to: {})

    Hash with the list of classes to include in the first Puppet run when $facts is Linux. Of each key-value of the hash, the key is used as marker to eventually override across Hiera hierarchies and the value is the name of the class to actually include. Any key name can be used, but the value must be a valid class existing the the $modulepath. If the value is set to empty string (”) then the class of the relevant marker is not included.

  • windows_classes (Psick::Class) (defaults to: {})

    Hash with the list of classes to include in the first Puppet run when $facts is windows.

  • solaris_classes (Psick::Class) (defaults to: {})

    Hash with the list of classes to include in the first Puppet run when $facts is Solaris.

  • darwin_classes (Psick::Class) (defaults to: {})

    Hash with the list of classes to include in the first Puppet run when $facts is Darwin.

  • reboot_apply (Enum['immediately','finished']) (defaults to: 'finished')

    The apply parameter to pass to reboot type

  • reboot_when (Enum['refreshed','pending']) (defaults to: 'refreshed')

    The when parameter to pass to reboot type

  • reboot_message (String) (defaults to: 'firstboot mode enabled, rebooting after first Puppet run')

    The message parameter to pass to reboot type

  • reboot_name (String) (defaults to: 'Rebooting')

    The name of the reboot type

  • reboot_timeout (Integer) (defaults to: 60)

    The timeout parameter to pass to reboot type

  • noop_manage (Boolean) (defaults to: $psick::noop_manage)

    If to use the noop() function for all the resources provided by this class. If this is true the noop function is called with $noop_value argument. This overrides any other noop setting (either set on client’s puppet.conf or by noop() function in main psick class). Default from psick class.

  • noop_value (Boolean) (defaults to: $psick::noop_value)

    The value to pass to noop() function if noop_manage is true. It applies to all the resources (and classes) declared in this class If true: noop metaparamenter is set to true, resources are not applied If false: noop metaparameter is set to false, and any eventual noop setting is overridden: resources are always applied. Default from psick class.

  • linux_reboot (Boolean) (defaults to: false)
  • windows_reboot (Boolean) (defaults to: true)
  • darwin_reboot (Boolean) (defaults to: false)
  • solaris_reboot (Boolean) (defaults to: false)
  • manage (Boolean) (defaults to: $psick::manage)


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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'manifests/firstrun.pp', line 86

class psick::firstrun (

  Psick::Class $linux_classes   = {},
  Psick::Class $windows_classes = {},
  Psick::Class $darwin_classes  = {},
  Psick::Class $solaris_classes = {},

  Boolean $linux_reboot   = false,
  Boolean $windows_reboot = true,
  Boolean $darwin_reboot  = false,
  Boolean $solaris_reboot = false,

  Enum['immediately','finished'] $reboot_apply = 'finished',
  Enum['refreshed','pending']    $reboot_when  = 'refreshed',
  String $reboot_message  = 'firstboot mode enabled, rebooting after first Puppet run',
  String $reboot_name     = 'Rebooting',
  Integer $reboot_timeout = 60,

  Boolean          $manage               = $psick::manage,
  Boolean          $noop_manage          = $psick::noop_manage,
  Boolean          $noop_value           = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    if !empty($linux_classes) and $facts['kernel'] == 'Linux' {
      $linux_classes.each |$n,$c| {
        if $c != '' {
          contain $c
          Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
        }
      }
    }
    if !empty($windows_classes) and $facts['kernel'] == 'windows' {
      $windows_classes.each |$n,$c| {
        if $c != '' {
          contain $c
          Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
        }
      }
    }
    if !empty($darwin_classes) and $facts['kernel'] == 'Darwin' {
      $darwin_classes.each |$n,$c| {
        if $c != '' {
          contain $c
          Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
        }
      }
    }
    if !empty($solaris_classes) and $facts['kernel'] == 'Solaris' {
      $solaris_classes.each |$n,$c| {
        if $c != '' {
          contain $c
          Class[$c] -> Psick::Puppet::Set_external_fact['firstrun']
        }
      }
    }

    # Reboot
    $kernel_down = downcase($facts['kernel'])
    $reboot = getvar("${kernel_down}_reboot")
    $fact_notify = $reboot ? {
      false => undef,
      true  => Reboot[$reboot_name],
    }

    psick::puppet::set_external_fact { 'firstrun':
      value  => 'done',
      notify => $fact_notify,
    }

    if $reboot {
      reboot { $reboot_name:
        apply   => $reboot_apply,
        message => $reboot_message,
        when    => $reboot_when,
        timeout => $reboot_timeout,
      }
    }
  }
}