Defined Type: tp::install::package

Defined in:
manifests/install/package.pp

Overview

This define installs the application (app) set in the given title. Default installation method is package. Alternative ones are possible if the necessary tinydta is present for the app. It manages the packages presence and, eventually, the relevant services on the supported Operating Systems. Several parameters allow any kind of override of default settings and customization. The list of supported applications, and the relevant OS coverage is in the data/ directory of the referred data_module.

Note: the version MUST be a valid for the underlying package provider. This setting is not used if there’s an array of packages to install

tp::install { 'elasticsearch':
  ensure => '4.0.1',
}

Note: this works when auto_conf is true (as default) AND when is defined $settings with a valid template in the used data module (default: tinydata)

tp::install { 'puppetserver':
  options_hash => lookup('puppetserver::options', {merge => deep}),
}

resources used to manage configuration files. Here eventual auto configuration is explicitly disabled

tp::install { 'puppet':
  conf_hash => lookup('puppet::tp_confs', {merge => deep}),,
  auto_conf => false,
}

Examples:

installation (of any any supported app and OS):

tp::install { $app: }

installation of postfix

tp::install { 'postfix': }

installation of a specific version of a package

installation of a package from its upstream repo, rather

than default OS based one. Relevant tinydata must be present.
 tp::install { 'mongodb':
   upstream_repo => true,
 }

installation and configuration via an options_hash

installation and configuration via a custom hash of tp::conf

installation with custom settings

tp::install { 'apache':
  settings => {
     package_name     => 'opt_apache',
     service_enable   => false,
     config_file_path => '/opt/apache/conf/httpd.conf',
     config_dir_path  => '/opt/apache/conf/',
   }
}

Installation of repo packages via proxy

tp::install { 'puppet':
  repo_exec_environment => [ 'http_proxy=http://proxy.domain:8080','https_proxy=http://proxy.domain:8080'],
}

Parameters:

  • ensure (Variant[Boolean,String]) (defaults to: present)

    Manage application presence. Valid values are present, absent or the package version number.

  • confs

    An hash of tp::conf resources to create. These resources will refer to the same application specified in the $title.

  • dirs

    An hash of tp::dir resources to create. These resources will refer to the same application specified in the $title.

  • options

    Generic hash of configuration parameters specific for the app, they are passed to tp::test if test_enable parameter is true

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

    An hash that can override the application settings tp returns, according to the underlying OS and the default behaviour

  • auto_prereq (Optional[Boolean]) (defaults to: undef)

    Boolean to enable automatic management of prerequisite dependencies required for the installation of the application. If they are defined in tp data.

  • data_module (String[1]) (defaults to: 'tinydata')

    Name of the module where tp data is looked for Default is tinydata: github.com/example42/tinydata

  • version (Optional[String]) (defaults to: undef)
  • base_package (Optional[String]) (defaults to: undef)
  • on_missing_data (Tp::Fail) (defaults to: pick(getvar('tp::on_missing_data'),'notify'))
  • auto_repo (Boolean) (defaults to: true)
  • auto_conf (Boolean) (defaults to: true)
  • auto_prerequisites (Optional[Boolean]) (defaults to: undef)
  • upstream_repo (Optional[Boolean]) (defaults to: undef)
  • repo (Variant[Undef,String]) (defaults to: undef)
  • repo_exec_environment (Array) (defaults to: [])
  • tp_repo_params (Hash) (defaults to: {})
  • manage_package (Boolean) (defaults to: true)
  • manage_service (Boolean) (defaults to: true)
  • apt_safe_trusted_key (Boolean) (defaults to: pick(getvar('tp::apt_safe_trusted_key'), false))


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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# File 'manifests/install/package.pp', line 86

define tp::install::package (

  Variant[Boolean,String] $ensure           = present,

  # V4
  Optional[String]        $version          = undef,
  Optional[String]        $base_package     = undef,
  Hash                    $settings         = {},
  Tp::Fail $on_missing_data = pick(getvar('tp::on_missing_data'),'notify'),

  Boolean                 $auto_repo        = true,
  Boolean                 $auto_conf        = true,
  Optional[Boolean]       $auto_prerequisites = undef,
  Optional[Boolean]       $auto_prereq      = undef,

  Optional[Boolean]       $upstream_repo    = undef,
  Variant[Undef,String]   $repo             = undef,
  Array                   $repo_exec_environment = [],
  Hash                    $tp_repo_params   = {},
  Boolean                 $manage_package   = true,
  Boolean                 $manage_service   = true,
  Boolean                 $apt_safe_trusted_key = pick(getvar('tp::apt_safe_trusted_key'), false),

  String[1]               $data_module      = 'tinydata',

) {
  $title_elements = split ($title, '::')
  $app = $title_elements[0]
  $real_base_package = pick($base_package,$title_elements[1],'main')
  $sane_app = regsubst($app, '/', '_', 'G')

  $package_provider = pick_default(getvar("settings.packages.${real_base_package}.package_provider"), getvar('settings.package_provider'))
  if $package_provider =~ Variant[Undef,String[0]] {
    $real_package_provider = undef
  } else {
    $real_package_provider = $package_provider
  }

  if $settings[package_source] =~ Variant[Undef,String[0]] {
    $package_source = undef
  } else {
    $package_source = tp::url_replace(getvar('settings.package_source'),tp::get_version($ensure,$version,$settings),tp::get_version($ensure,$version,$settings,'major'))
  }

  if $settings[package_install_options] == Variant[Undef,String[0]] {
    $package_install_options = undef
  } else {
    $package_install_options = $settings[package_install_options]
  }

  $plain_ensure = $ensure ? {
    'absent' => 'absent',
    false    => 'absent',
    default  => 'present',
  }

  # Automatic repo management
  $use_upstream_repo = pick($upstream_repo,$settings[upstream_repo],false)
  if $auto_repo
  and ( $settings[repo_url]
    or $settings[yum_mirrorlist]
    or $settings[repo_package_url]
  or $settings[repo_file_url]) {
    $repo_enabled = $ensure ? {
      'absent'  => false,
      false     => false,
      default   => true,
    }
    $tp_repo_params_default = {
      enabled              => $repo_enabled,
      before               => Package[$settings[package_name]],
      data_module          => $data_module,
      repo                 => $repo,
      settings_hash        => $settings,
      exec_environment     => $repo_exec_environment,
      upstream_repo        => $use_upstream_repo,
      apt_safe_trusted_key => $apt_safe_trusted_key,
    }
    tp::repo { $app:
      * => $tp_repo_params_default + $tp_repo_params,
    }
  }

  if $auto_prerequisites {
    deprecation('auto_prerequisites','Ignored. Parameter renamed to auto_prereq. s/auto_prerequisites/auto_prereq')
  }

  # Automatic dependencies management, if data defined
  if $auto_prereq and $settings[package_prerequisites] and $ensure != 'absent' {
    case $settings[package_prerequisites] {
      Array: {
        $settings[package_prerequisites].each | $p | {
          if $settings[package_name] {
            Package[$p] -> Package[$settings[package_name]]
          }
          ensure_packages($p)
        }
      }
      Hash: {
        $settings[package_prerequisites].each | $p,$v | {
          if $settings[package_name] {
            Package[$p] -> Package[$settings[package_name]]
          }
          ensure_packages($p, $v)
        }
      }
      String: {
        if $settings[package_name] {
          Package[$settings[package_prerequisites]] -> Package[$settings[package_name]]
        }
        package { $settings[package_prerequisites]: }
        # ensure_packages("${settings[package_prerequisites]}")
      }
      default: {}
    }
  }
  if $auto_prereq and $settings[tp_prerequisites] and $ensure != 'absent' {
    case $settings[tp_prerequisites] {
      Array: {
        $settings[tp_prerequisites].each | $p | {
          if $settings[package_name] {
            Tp::Install[$p] -> Package[$settings[package_name]]
          }
          tp_install($p, { auto_prereq => true })
        }
      }
      Hash: {
        $settings[tp_prerequisites].each | $p,$v | {
          if $settings[package_name] {
            Tp::Install[$p] -> Package[$settings[package_name]]
          }
          $tp_install_params = { auto_prereq => true } + $v
          tp_install($p, $tp_install_params)
        }
      }
      String: {
        if $settings[package_name] {
          Tp::Install[$settings[tp_prerequisites]] -> Package[$settings[package_name]]
        }
        tp_install($settings[tp_prerequisites], { auto_prereq => true })
      }
      default: {}
    }
  }
  if $auto_prereq and $settings['exec_prerequisites'] and $ensure != 'absent' {
    $settings[exec_prerequisites].each | $k , $v | {
      if $settings[package_name] {
        Exec[$k] -> Package[$settings[package_name]]
      }
      exec { $k:
        * => { 'path' => $facts['path'] } + $v,
      }
    }
  }
  if $auto_prereq and $settings['extra_prerequisites'] and $ensure != 'absent' {
    $settings['extra_prerequisites'].each | $k,$v | {
      create_resources($k,$v, { before => Package[$settings[package_name]] })
    }
  }
  if $auto_prereq and $settings['exec_postinstall'] and $ensure != 'absent' {
    $settings[exec_postinstall].each | $k , $v | {
      if $settings[package_name] {
        Package[$settings[package_name]] -> Exec["${app} - ${k}"]
      }
      exec { "${app} - ${k}":
        * => { 'path' => '/bin:/usr/bin:/sbin:/usr/sbin' } + $v,
      }
    }
  }
  if $auto_prereq and $settings['extra_postinstall'] and $ensure != 'absent' {
    $settings['extra_postinstall'].each | $k,$v | {
      create_resources($k,$v, { require => Package[$settings[package_name]] })
    }
  }

  # Resources
  $packages = pick_default(getvar('settings.package_name'), getvar('settings.packages.main.name'))

  if $manage_package {
    case $packages {
      Hash: {
        $package_defaults = {
          ensure   => $plain_ensure,
          provider => $real_package_provider,
        }
        $packages.each |$kk,$vv| {
          package { $kk:
            * => $package_defaults + pick($settings[package_params], {} + $vv),
          }
        }
      }
      Array: {
        $package_defaults = {
          ensure   => $plain_ensure,
          provider => $real_package_provider,
        }
        $packages.each |$k| {
          package { $k:
            * => $package_defaults + pick($settings[package_params], {}),
          }
        }
      }
      String[1]: {
        $package_defaults = {
          ensure          => pick($version,$ensure),
          provider        => $real_package_provider,
          source          => $package_source,
          install_options => $package_install_options,
        }
        package { $packages:
          * => $package_defaults + pick($settings[package_params], {}),
        }
      }
      Undef: {
        # do nothing
      }
      default: {
        # do nothing
#        tp::fail($on_missing_data, "tp::install::package ${app} - No data for ${packages}. Valid types are String, Array, Hash, Undef.")
      }
    }
  }

  $services = pick_default(getvar('settings.services'), getvar('settings.service_name'),undef)
  if $manage_service {
    $service_ensure = $ensure ? {
      'absent' => 'stopped',
      false    => 'stopped',
      default  => $settings[service_ensure],
    }
    $service_enable = $ensure ? {
      'absent' => false,
      false    => false,
      default  => $settings[service_enable],
    }
    $service_require = $packages ? {
      Hash      => Package[$packages.keys],
      Array     => Package[$packages],
      String[1] => Package[$packages],
      default   => undef,
    }
    case $services {
      Hash: {
        $service_defaults = {
          ensure  => $service_ensure,
          enable  => $service_enable,
          require => $service_require,
        }
        $services.each |$kk,$vv| {
          service { $kk:
            * => $service_defaults + pick(getvar("settings.services.${kk}.params"), getvar('settings.service_params'), {}),
          }
        }
      }
      Array: {
        $service_defaults = {
          ensure  => $service_ensure,
          enable  => $service_enable,
          require => $service_require,
        }
        $services.each |$k| {
          service { $k:
            * => $service_defaults + pick(getvar("settings.services.${k}.params"), getvar('settings.service_params'), {}),
          }
        }
      }
      String[1]: {
        $service_defaults = {
          ensure  => $service_ensure,
          enable  => $service_enable,
          require => $service_require,
        }
        service { $services:
          * => $service_defaults + pick(getvar("settings.services.${services}.params"), getvar('settings.service_params'), {}),
        }
      }
      Undef: {
        # do nothing
      }
      '': {
        # do nothing
      }
      default: {
        tp::fail($on_missing_data,"tp::install::package ${app} - Unsupported type for ${services}. Valid types are String, Array, Hash, Undef.") # lint:ignore:140chars
      }
    }
  }
}