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:

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

    If to actually manage any resource in this profile or not

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

  • no_noop (Boolean) (defaults to: false)

    Set noop metaparameter to false to all the resources of this class. This overrides client site noop setting but not $psick::noop_mode.

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


61
62
63
64
65
66
67
68
69
70
71
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
# File 'manifests/packages.pp', line 61

class psick::packages (
  Boolean $manage                  = $::psick::manage,

  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 $no_noop                 = false,

) {

  if $manage {
    if !$::psick::noop_mode and $no_noop {
      info('Forced no-noop mode in psick::packages')
      noop(false)
    }
    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 $::osfamily == $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")
          }
        }
      }
    }
  }
}