Defined Type: tp::stdmod

Defined in:
manifests/stdmod.pp

Overview

Define: tp::stdmod

This defines reproduces a standard module based on a this stdmod standard template (github.com/stdmod/puppet-skeleton-standard)

The define exposes stdmod compliant parameters for standard package, service, configuration setups.

Parameters:

  • package_name (Variant[Undef,String]) (defaults to: undef)
  • package_ensure (Variant[Undef,Boolean,String]) (defaults to: 'present')
  • service_name (Variant[Undef,String]) (defaults to: undef)
  • service_ensure (Variant[Undef,String]) (defaults to: undef)
  • service_enable (Variant[Undef,Boolean]) (defaults to: undef)
  • config_file_path (Variant[Undef,String]) (defaults to: undef)
  • config_file_replace (Variant[Undef,String,Boolean]) (defaults to: undef)
  • config_file_require (Variant[Undef,String,Boolean]) (defaults to: undef)
  • config_file_notify (Variant[Undef,String,Boolean]) (defaults to: 'default')
  • config_file_source (Variant[Undef,String]) (defaults to: undef)
  • config_file_template (Variant[Undef,String]) (defaults to: undef)
  • config_file_epp (Variant[Undef,String]) (defaults to: undef)
  • config_file_content (Variant[Undef,String]) (defaults to: undef)
  • config_file_options_hash (Variant[Undef,Hash]) (defaults to: undef)
  • config_file_owner (Variant[Undef,String]) (defaults to: undef)
  • config_file_group (Variant[Undef,String]) (defaults to: undef)
  • config_file_mode (Variant[Undef,String]) (defaults to: undef)
  • config_dir_path (Variant[Undef,String]) (defaults to: undef)
  • config_dir_source (Variant[Undef,String]) (defaults to: undef)
  • config_dir_purge (Variant[Undef,Boolean]) (defaults to: undef)
  • config_dir_force (Variant[Undef,Boolean]) (defaults to: undef)
  • config_dir_recurse (Variant[Undef,Boolean]) (defaults to: undef)
  • dependency_class (Variant[Undef,String]) (defaults to: undef)
  • monitor_class (Variant[Undef,String]) (defaults to: undef)
  • firewall_class (Variant[Undef,String]) (defaults to: undef)
  • debug (Variant[Undef,Boolean]) (defaults to: false)
  • debug_dir (Variant[Undef,String]) (defaults to: '/tmp')
  • data_module (Variant[Undef,String]) (defaults to: 'tinydata')


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

define tp::stdmod (

  Variant[Undef,String]         $package_name              = undef,
  Variant[Undef,Boolean,String] $package_ensure            = 'present',

  Variant[Undef,String]         $service_name              = undef,
  Variant[Undef,String]         $service_ensure            = undef,
  Variant[Undef,Boolean]        $service_enable            = undef,

  Variant[Undef,String]         $config_file_path          = undef,
  Variant[Undef,String,Boolean] $config_file_replace       = undef,
  Variant[Undef,String,Boolean] $config_file_require       = undef,
  Variant[Undef,String,Boolean] $config_file_notify        = 'default',
  Variant[Undef,String]         $config_file_source        = undef,
  Variant[Undef,String]         $config_file_template      = undef,
  Variant[Undef,String]         $config_file_epp           = undef,
  Variant[Undef,String]         $config_file_content       = undef,
  Variant[Undef,Hash]           $config_file_options_hash  = undef,
  Variant[Undef,String]         $config_file_owner         = undef,
  Variant[Undef,String]         $config_file_group         = undef,
  Variant[Undef,String]         $config_file_mode          = undef,

  Variant[Undef,String]         $config_dir_path           = undef,
  Variant[Undef,String]         $config_dir_source         = undef,
  Variant[Undef,Boolean]        $config_dir_purge          = undef,
  Variant[Undef,Boolean]        $config_dir_force          = undef,
  Variant[Undef,Boolean]        $config_dir_recurse        = undef,

  Variant[Undef,String]         $dependency_class          = undef,
  Variant[Undef,String]         $monitor_class             = undef,
  Variant[Undef,String]         $firewall_class            = undef,

  Variant[Undef,Boolean]        $debug                     = false,
  Variant[Undef,String]         $debug_dir                 = '/tmp',

  Variant[Undef,String]         $data_module               = 'tinydata',

) {
  # Settings evaluation
  $tp_settings = tp_lookup($title,'settings',$data_module,'deep_merge')
  $user_settings = {
    package_name              => $package_name,
    package_ensure            => $package_ensure,
    service_name              => $service_name,
    service_ensure            => $service_ensure,
    service_enable            => $service_enable,
    config_file_path          => $config_file_path,
    config_file_replace       => $config_file_replace,
    config_file_require       => $config_file_require,
    config_file_notify        => $config_file_notify,
    config_file_owner         => $config_file_owner,
    config_file_group         => $config_file_group,
    config_file_mode          => $config_file_mode,
    config_dir_path           => $config_dir_path,
    config_dir_purge          => $config_dir_purge,
    config_dir_force          => $config_dir_force,
    config_dir_recurse        => $config_dir_recurse,
  }
  $user_settings_clean = delete_undef_values($user_settings)
  $settings = $tp_settings + $user_settings_clean

  if $config_file_content {
    $manage_config_file_content = $config_file_content
  } elsif $config_file_template {
    $template_ext = $config_file_template[-4,4]
    $manage_config_file_content = $template_ext ? {
      '.epp'  => epp($config_file_template),
      '.erb'  => template($config_file_template),
      default => template($config_file_template),
    }
  } elsif $config_file_epp {
    $manage_config_file_content = epp($config_file_epp)
  } else {
    $manage_config_file_content = undef
  }

  $manage_config_file_require = "Package[${settings[package_name]}]"
  $manage_config_file_notify  = $config_file_notify ? {
    'default' => "Service[${settings[service_name]}]",
    'undef'   => undef,
    ''        => undef,
    default   => $config_file_notify,
  }

  if $package_ensure == 'absent' {
    $manage_service_enable = false
    $manage_service_ensure = stopped
    $config_dir_ensure = absent
    $config_file_ensure = absent
  } else {
    $manage_service_enable = $service_enable ? {
      ''      => undef,
      undef   => true,
      default => $service_enable,
    }
    $manage_service_ensure = $service_ensure ? {
      ''      => undef,
      undef   => 'running',
      default => $service_ensure,
    }
    $config_dir_ensure = directory
    $config_file_ensure = file
  }

  # Dependency class
  if $dependency_class and $dependency_class != '' {
    include $dependency_class
  }

  # Resources
  if $settings['package_name'] {
    package { $settings['package_name']:
      ensure => $settings['package_ensure'],
    }
  }

  if $settings['service_name'] {
    service { $settings['service_name']:
      ensure => $manage_service_ensure,
      enable => $manage_service_enable,
    }
  }

  if $settings['config_file_path'] and
  ( $config_file_source
    or $manage_config_file_content
  or $config_file_ensure == 'absent' ) {
    file { $settings[config_file_path]:
      ensure  => $config_file_ensure,
      path    => $settings[config_file_path],
      mode    => $settings[config_file_mode],
      owner   => $settings[config_file_owner],
      group   => $settings[config_file_group],
      source  => $settings[config_file_source],
      content => $manage_config_file_content,
      notify  => $manage_config_file_notify,
      require => $manage_config_file_require,
    }
  }

  if $config_dir_source {
    file { $settings[config_dir_path]:
      ensure  => $config_dir_ensure,
      path    => $settings[config_dir_path],
      source  => $config_dir_source,
      recurse => $settings[config_dir_recurse],
      purge   => $settings[config_dir_purge],
      force   => $settings[config_dir_force],
      notify  => $manage_config_file_notify,
      require => $manage_config_file_require,
    }
  }

  # Extra classes
  if $monitor_class and $monitor_class != '' {
    include $monitor_class
  }
  if $firewall_class and $firewall_class != '' {
    include $firewall_class
  }

  # Debugging
  if $debug == true {
    $debug_scope = inline_template('<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime.*|path|timestamp|free|.*password.*)/ } %>')
    file { "tp_stdmod_debug_${title}":
      ensure  => $config_file_ensure ,
      content => $debug_scope,
      path    => "${debug_dir}/tp_stdmod_debug_${title}",
    }
  }
}