Defined Type: tp::setup

Defined in:
manifests/setup.pp

Summary

Setups an application from source build or release tarball

Overview

This defines setups an application copying files to target locations, eventually configuring the relevant service and user

Examples:

tp::setup { 'namevar': }

Parameters:

  • install_method (Tp::Install_method)
  • app (String)
  • source_dir (Optional[StdLib::Absolutepath]) (defaults to: undef)
  • ensure (Variant[Boolean,String]) (defaults to: present)
  • version (Optional[String]) (defaults to: undef)
  • on_missing_data (Tp::Fail) (defaults to: pick(getvar('tp::on_missing_data'),'notify'))
  • settings (Hash) (defaults to: {})
  • owner (String[1]) (defaults to: pick(getvar('identity.user'),'root'))
  • group (String[1]) (defaults to: pick(getvar('identity.group'),'root'))


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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
# File 'manifests/setup.pp', line 8

define tp::setup (
  Tp::Install_method $install_method,
  String $app,
  Optional[StdLib::Absolutepath] $source_dir = undef,
  Variant[Boolean,String] $ensure             = present,
  Optional[String] $version  = undef,
  Tp::Fail $on_missing_data = pick(getvar('tp::on_missing_data'),'notify'),
  Hash $settings                              = {},

  String[1] $owner = pick(getvar('identity.user'),'root'),
  String[1] $group = pick(getvar('identity.group'),'root'),
) {
  $destination_dir = $tp::real_tp_params['destination']['path']

  # Setup settings are a result from the merge of keys settings.$install_method.setup and settings.setup
  $setup_settings = deep_merge(getvar('settings.setup', {}),getvar("settings.${install_method}.setup", {}))

  $real_version = tp::get_version($ensure,$version,$setup_settings)
  $real_majversion = tp::get_version($ensure,$version,$setup_settings,'major')

  if pick(getvar('setup_settings.enable'), false ) {
    if pick(getvar('setup_settings.manage_service'), false ) {
      $before_tp_service = Tp::Service[$app]
      tp::service { $app:
        ensure          => $ensure,
        on_missing_data => $on_missing_data,
        settings        => $settings,
        my_options      => getvar('setup_settings.systemd_options', {}),
        systemd_symlink => pick_default(getvar('setup_settings.systemd_symlink')),
      }
    } else {
      $before_tp_service = undef
    }

    $files = getvar('setup_settings.files', {})
    if $source_dir {
      case $files {
        Hash: {
          $files.each | $k,$v | {
            tp::copy_file { $k:
              ensure => pick($v['ensure'],$ensure),
              path   => pick($v['path'], "${destination_dir}/${k}"),
              owner  => pick($v['owner'], $owner),
              group  => pick($v['group'], $group),
              mode   => pick($v['mode'], '0755'),
              source => pick($v['source'],"${source_dir}/${k}"),
              before => $before_tp_service,
            }
          }
        }
        Array: {
          $files.each | $k | {
            tp::copy_file { "${destination_dir}/${k}":
              ensure => $ensure,
              path   => "${destination_dir}/${k}",
              owner  => $owner,
              group  => $group,
              source => "${source_dir}/${k}",
              mode   => '0755',
              before => $before_tp_service,
            }
          }
        }
        String: {
          tp::copy_file { "${destination_dir}/${files}":
            ensure => $ensure,
            path   => "${destination_dir}/${files}",
            owner  => $owner,
            group  => $group,
            source => "${source_dir}/${files}",
            mode   => '0755',
            before => $before_tp_service,
          }
        }
        default: {
          tp::fail($on_missing_data, "tp::setup ${app} - Missing tinydata: settings.setup.files or settings.${install_method}.setup.files is not a Hash, Array or String") # lint:ignore:140chars
        }
      }
    }

    $links = getvar('setup_settings.links', {})
    $links.each | $k,$v | {
      file { $k:
        ensure => link,
        target => tp::url_replace($v,$real_version,$real_majversion),
        before => $before_tp_service,
      }
    }

    if pick(getvar('setup_settings.manage_user'), false) and getvar('setup_settings.process_user') {
      user { getvar('setup_settings.process_user'):
        ensure     => $ensure,
        managehome => true,
        before     => $before_tp_service,
      }
    }

    if getvar('setup_settings.resources') and $ensure != 'absent' {
      tp::create_everything ( getvar('setup_settings.resources'), { 'before' => $before_tp_service })
    }
  }
}