Puppet Class: puppetboard

Defined in:
manifests/init.pp

Summary

Base class for Puppetboard. Sets up the user and python environment.

Overview

class { ‘puppetboard’:

  user  => 'pboard',
  group => 'pboard',
  basedir => '/www/puppetboard'
} ->
class { 'puppetboard::apache::conf':
  user  => 'pboard',
  group => 'pboard',
  basedir => '/www/puppetboard'
}

Examples:

configure puppetboard with an apache config for a subpath (http://$fqdn/puppetboard)

Parameters:

  • install_from (Enum['package', 'pip', 'vcsrepo']) (defaults to: 'pip')

    Specify how the app should be installed

  • user (String) (defaults to: 'puppetboard')

    Puppetboard system user.

  • homedir (Optional[Stdlib::Absolutepath]) (defaults to: undef)

    Puppetboard system user’s home directory.

  • group (String) (defaults to: 'puppetboard')

    Puppetboard system group.

  • groups (Optional[Variant[String[1], Array[String[1]]]]) (defaults to: undef)

    additional groups for the user that runs puppetboard

  • basedir (Stdlib::AbsolutePath) (defaults to: '/srv/puppetboard')

    Base directory where to build puppetboard vcsrepo and python virtualenv.

  • git_source (String) (defaults to: 'https://github.com/voxpupuli/puppetboard')

    Location of upstream Puppetboard GIT repository

  • puppetdb_host (String) (defaults to: '127.0.0.1')

    PuppetDB Host

  • puppetdb_port (Stdlib::Port) (defaults to: 8080)

    PuppetDB Port

  • puppetdb_key (Optional[Stdlib::AbsolutePath]) (defaults to: undef)

    path to PuppetMaster/CA signed client SSL key

  • puppetdb_ssl_verify (Variant[Boolean, Stdlib::AbsolutePath]) (defaults to: false)

    whether PuppetDB uses SSL or not (true or false), or the path to the puppet CA

  • puppetdb_cert (Optional[Stdlib::AbsolutePath]) (defaults to: undef)

    path to PuppetMaster/CA signed client SSL cert

  • puppetdb_timeout (Integer[0]) (defaults to: 20)

    timeout, in seconds, for connecting to PuppetDB

  • unresponsive (Integer[0]) (defaults to: 3)

    number of hours after which a node is considered “unresponsive”

  • enable_catalog (Boolean) (defaults to: false)

    Whether to allow the user to browser catalog comparisons.

  • enable_query (Boolean) (defaults to: true)

    Whether to allow the user to run raw queries against PuppetDB.

  • offline_mode (Boolean) (defaults to: false)

    Weather to load static assents (jquery, semantic-ui, tablesorter, etc)

  • localise_timestamp (Boolean) (defaults to: true)

    Whether to localise the timestamps in the UI.

  • python_loglevel (Puppetboard::Syslogpriority) (defaults to: 'info')

    Python logging module log level.

  • python_proxy (Optional[String[1]]) (defaults to: undef)

    HTTP proxy server to use for pip/virtualenv.

  • python_index (Optional[String[1]]) (defaults to: undef)

    HTTP index server to use for pip/virtualenv.

  • python_systempkgs (Boolean) (defaults to: false)

    Python system packages available in virtualenv.

  • default_environment (String[1]) (defaults to: 'production')

    set the default environment

  • revision (Optional[String]) (defaults to: undef)

    Commit, tag, or branch from Puppetboard’s Git repo to be used

  • version (Variant[Enum['latest'], String[1]]) (defaults to: 'latest')

    PyPI package version to be installed

  • use_pre_releases (Boolean) (defaults to: false)

    if version is set to ‘latest’, then should pre-releases be used too?

  • manage_git (Boolean) (defaults to: false)

    If true, require the git package. If false do nothing.

  • manage_virtualenv (Boolean) (defaults to: false)

    If true, require the virtualenv package. If false do nothing.

  • python_version (Python::Version)

    Python version to use in virtualenv.

  • virtualenv_dir (Stdlib::Absolutepath) (defaults to: "${basedir}/virtenv-puppetboard")

    Set location where virtualenv will be installed

  • manage_user (Boolean) (defaults to: true)

    If true, manage (create) this group. If false do nothing.

  • manage_group (Boolean) (defaults to: true)

    If true, manage (create) this group. If false do nothing.

  • package_name (Optional[String[1]]) (defaults to: undef)

    Name of the package to install puppetboard

  • manage_selinux (Boolean) (defaults to: pick($facts['os.selinux.enabled'], false))

    If true, manage selinux policies for puppetboard. If false do nothing.

  • reports_count (Integer[0]) (defaults to: 10)

    This is the number of reports that we want the dashboard to display.

  • settings_file (Stdlib::Absolutepath) (defaults to: "${basedir}/puppetboard/settings.py")

    Path to puppetboard configuration file

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

    Defaults to an empty hash ‘{}’. Used to pass in arbitrary key/value

  • override (Variant[Array[String[1]], String[1]]) (defaults to: ['None'])

    Sets the Apache AllowOverride value

  • enable_ldap_auth (Boolean) (defaults to: false)

    Whether to enable LDAP auth

  • ldap_require_group (Boolean) (defaults to: false)

    LDAP group to require on login

  • apache_confd (Stdlib::Absolutepath)

    path to the apache2 vhost directory

  • apache_service (String[1])

    name of the apache2 service

  • secret_key (Optional[String[1]]) (defaults to: undef)

    used for CSRF prevention and more. It should be a long, secret string, the same for all instances of the app. Required since Puppetboard 5.0.0.



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

class puppetboard (
  Stdlib::Absolutepath $apache_confd,
  String[1] $apache_service,
  Python::Version $python_version,
  Enum['package', 'pip', 'vcsrepo'] $install_from             = 'pip',
  Boolean $manage_selinux                                     = pick($facts['os.selinux.enabled'], false),
  String $user                                                = 'puppetboard',
  Optional[Stdlib::Absolutepath] $homedir                     = undef,
  String $group                                               = 'puppetboard',
  Optional[Variant[String[1], Array[String[1]]]] $groups      = undef,
  Stdlib::AbsolutePath $basedir                               = '/srv/puppetboard',
  String $git_source                                          = 'https://github.com/voxpupuli/puppetboard',
  String $puppetdb_host                                       = '127.0.0.1',
  Stdlib::Port $puppetdb_port                                 = 8080,
  Optional[Stdlib::AbsolutePath] $puppetdb_key                = undef,
  Variant[Boolean, Stdlib::AbsolutePath] $puppetdb_ssl_verify = false,
  Optional[Stdlib::AbsolutePath] $puppetdb_cert               = undef,
  Integer[0] $puppetdb_timeout                                = 20,
  Integer[0] $unresponsive                                    = 3,
  Boolean $enable_catalog                                     = false,
  Boolean $enable_query                                       = true,
  Boolean $localise_timestamp                                 = true,
  Puppetboard::Syslogpriority $python_loglevel                = 'info',
  Optional[String[1]] $python_proxy                           = undef,
  Optional[String[1]] $python_index                           = undef,
  Boolean $python_systempkgs                                  = false,
  Optional[String] $revision                                  = undef,
  Boolean $manage_user                                        = true,
  Boolean $manage_group                                       = true,
  Optional[String[1]] $package_name                           = undef,
  Boolean $manage_git                                         = false,
  Boolean $manage_virtualenv                                  = false,
  Stdlib::Absolutepath $virtualenv_dir                        = "${basedir}/virtenv-puppetboard",
  Integer[0] $reports_count                                   = 10,
  String[1] $default_environment                              = 'production',
  Boolean $offline_mode                                       = false,
  Stdlib::Absolutepath $settings_file                         = "${basedir}/puppetboard/settings.py",
  Hash $extra_settings                                        = {},
  Variant[Array[String[1]], String[1]] $override              = ['None'],
  Boolean $enable_ldap_auth                                   = false,
  Boolean $ldap_require_group                                 = false,
  Variant[Enum['latest'], String[1]] $version                 = 'latest',
  Boolean $use_pre_releases                                   = false,
  Optional[String[1]] $secret_key                             = undef,
) {
  if !$secret_key {
    $message = join([
        "Starting with Puppetboard 5.0.0 providing own \$secret_key is required.",

        'See https://github.com/voxpupuli/puppetboard/issues/721 for more info.',

        'If you run Puppetboard on a single node with static FQDN then you can set it the following code',
        "to generate a random but not changing value: \${fqdn_rand_string(32)}",
    ], ' ')

    if $version == 'latest' or versioncmp($version, '5.0.0') >= 0 {
      fail($message)
    } else {
      notify { 'Warning':
        message => $message,
      }
    }
  }

  if $manage_group {
    group { $group:
      ensure => present,
      system => true,
    }
  }

  if $manage_user {
    user { $user:
      ensure     => present,
      shell      => '/bin/sh',
      home       => $homedir,
      managehome => true,
      gid        => $group,
      system     => true,
      groups     => $groups,
      require    => Group[$group],
    }
  }

  $pyvenv_proxy_env = $python_proxy ? {
    undef   => [],
    default => [
      "HTTP_PROXY=${python_proxy}",
      "HTTPS_PROXY=${python_proxy}",
    ]
  }

  if $install_from in ['pip', 'vcsrepo'] {
    file { $basedir:
      ensure => 'directory',
      owner  => $user,
      group  => $group,
      mode   => '0755',
    }
  }

  case $install_from {
    'package': {
      package { $package_name:
        ensure => installed,
      }
    }
    'pip': {
      if $revision {
        fail("'pip' installation method uses \$version parameter to specify version, not \$revision.")
      }

      file { "${basedir}/puppetboard":
        ensure  => directory,
        recurse => true,
        force   => true,
        purge   => true, # such cleanup is needed in case of a switch from install_from=vcsrepo to install_from=pip
      }

      python::pyvenv { $virtualenv_dir:
        ensure      => present,
        version     => $python_version,
        systempkgs  => $python_systempkgs,
        owner       => $user,
        group       => $group,
        require     => File[$basedir],
        environment => $pyvenv_proxy_env,
      }

      $install_args = $use_pre_releases ? {
        true    => '--pre',
        default => undef,
      }

      python::pip { 'puppetboard':
        ensure       => $version,
        virtualenv   => $virtualenv_dir,
        proxy        => $python_proxy,
        owner        => $user,
        group        => $group,
        require      => Python::Pyvenv[$virtualenv_dir],
        install_args => $install_args,
      }
    }
    'vcsrepo': {
      if $version != 'latest' {
        fail("'vcsrepo' installation method uses \$revision parameter to specify version, not \$version.")
      }

      notify { 'Not recommended':
        message => "This installation method is recommended mainly for the contributors to voxpupuli/puppetboard.
                    Consider switching to 'pip' if you are not one of them.",
      }

      vcsrepo { "${basedir}/puppetboard":
        ensure   => present,
        provider => git,
        user     => $user,
        source   => $git_source,
        revision => $revision,
        require  => [
          User[$user],
          Group[$group],
        ],
        before   => [
          File[$settings_file],
        ],
        notify   => Python::Requirements["${basedir}/puppetboard/requirements.txt"],
      }

      python::pyvenv { $virtualenv_dir:
        ensure      => present,
        version     => $python_version,
        systempkgs  => false,
        owner       => $user,
        group       => $group,
        require     => Vcsrepo["${basedir}/puppetboard"],
        environment => $pyvenv_proxy_env,
      }

      python::requirements { "${basedir}/puppetboard/requirements.txt":
        virtualenv => $virtualenv_dir,
        proxy      => $python_proxy,
        owner      => $user,
        group      => $group,
      }
    }
    default: {
      fail("Unsupported installation method: ${install_from}")
    }
  }

  file { $settings_file:
    ensure  => 'file',
    group   => $group,
    mode    => '0644',
    owner   => $user,
    content => template('puppetboard/settings.py.erb'),
  }

  if $manage_git and !defined(Package['git']) {
    package { 'git':
      ensure => installed,
    }
  }

  if $manage_virtualenv {
    class { 'python':
      version => $python_version,
      dev     => 'present',
      venv    => 'present',
    }
    Class['python'] -> Class['puppetboard']
  }

  if $manage_selinux {
    selboolean { 'httpd_can_network_relay':
      persistent => true,
      value      => 'on',
    }
    selboolean { 'httpd_can_network_connect':
      persistent => true,
      value      => 'on',
    }
    selboolean { 'httpd_can_network_connect_db':
      persistent => true,
      value      => 'on',
    }
  }
}