Puppet Class: psick::packages

Defined in:
manifests/packages.pp

Summary

Generic class to manage packages

Overview

This class exposes entrypoints, and data defaults to manage system packages, expressed via arrays or hashes. Be aware of risks of duplicated resources, when specifying here packages that might be installed by other modules or classes. You can use different parameters to manage packages, they all manage package resources, using different approaches:

  • $packages_list An Array of packages to install. If $add_default_packages

    if true, to this list is added the $packages_default array
    
  • $packages_hash An Hash of packages to manage, where keys are package names

    and values are arguments passed to the package resurce
    
  • $packages_osfamily_hash An Hash of packages to manage, where keys are the

    osfamily and values are a String, an Array of an
    Hash of packages to manage.
    

Windows)

psick::packages::resource_default_arguments:
  provider: chocolatey
psick::packages::packages_list:
  - "firefox"
  - "flashplayerplugin"

psick::packages::delete_unmanaged: true

Examples:

Install an array of packages and use chocolatey as provider (on

Alternative approach with different package names for different OS

families. The list of packages for each $osfamily can be either a string,
an array or an hash (allowing you to specify extra params for each package):
 psick::packages::packages_osfamily_hash:
   RedHat:
     - net-tools
     - telnet
   Debian: telnet
   windows:
     firefox:
       provider: chocolatey

Purge all the packages not managed explicitly by Puppet.

Warning: This is a very dangerous option, as it can remove necessary
system packages from your nodes

Parameters:

  • packages_list (Array) (defaults to: [])

    An array of custom extra packages to install

  • packages_default (Array) (defaults to: [])

    The packages installed by default (according to the underlying OS settings)

  • add_default_packages (Boolean) (defaults to: true)

    If to actually install the default packages

  • packages_hash (Hash) (defaults to: {})

    An Hash passed to create packages resources. It has the same function of $packages_list array, but allows specification of parameters for package type.

  • $packages_osfamily_hash

    This hash is an alternative way to specify the packages to install for each osfamily. The key of the Hash is the Osfamily, the relevant value can be a String, an Array or an Hash of packages to install

  • delete_unmanaged (Boolean) (defaults to: false)

    If true all packages not managed by Puppet are automatically deleted. WARNING: this option may remove packages you need on your systems!

  • resource_default_arguments (Hash) (defaults to: {})

    An hash of arguments to be used as default in the package type.

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

    If to actually manage any resource in this class. If false no resource is managed. Default value is taken from main psick class.

  • 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.

  • packages_osfamily_hash (Hash) (defaults to: {})


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
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
# File 'manifests/packages.pp', line 72

class psick::packages (
  Array $packages_list             = [],
  Array $packages_default          = [],
  Boolean $add_default_packages    = true,

  Hash $packages_hash              = {},

  Hash $packages_osfamily_hash     = {},

  Hash $resource_default_arguments = {},
  Boolean $delete_unmanaged        = false,

  Boolean $manage                  = $psick::manage,
  Boolean $noop_manage             = $psick::noop_manage,
  Boolean $noop_value              = $psick::noop_value,

) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    Package {
      * => $resource_default_arguments,
    }

    # Purge umanaged packages if $delete_unmanaged == true (DANGER!)
    if $delete_unmanaged {
      resources { 'package':
        purge => true,
      }
    }

    # Packages management based on $packages_list
    $packages = $add_default_packages ? {
      true  => $packages_list + $packages_default,
      false => $packages_list,
    }
    $packages.each |$pkg| {
      ensure_packages($pkg)
    }

    # Packages management based on $packages_hash
    $packages_hash.each |$k,$v| {
      package { $k:
        * => $v,
      }
    }

    # Packages management based on $packages_osfamily_hash
    $packages_osfamily_hash.each |$k,$v| {
      if $facts['os']['family'] == $k {
        case $v {
          Array: {
            ensure_packages($v)
          }
          Hash: {
            $v.each |$kk,$vv| {
              package { $kk:
                * => $vv,
              }
            }
          }
          String: {
            package { $v:
              ensure => present,
            }
          }
          default: {
            fail("Unsupported type for ${v}. Valid types are String, Array, Hash")
          }
        }
      }
    }
  }
}