Puppet Class: jenkins::user_setup

Defined in:
manifests/user_setup.pp

Summary

Optionally create the jenkins user and make sure all directories have proper permissions setup.

Overview

By having this in a separate class that is managed before installing the package, we can effectivly override the default local dir that is otherwise possibly created by the package.



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

class jenkins::user_setup {
  assert_private()

  $dir_params = {
    ensure => directory,
    owner  => $jenkins::user,
    group  => $jenkins::group,
    mode   => '0755',
  }

  # ensure_resource is used to try to maintain backwards compatiblity with
  # manifests that were able to external declare resources due to the
  # old conditional behavior of jenkins::plugin
  if $jenkins::manage_user {
    ensure_resource('user', $jenkins::user, {
        ensure     => present,
        gid        => $jenkins::group,
        home       => $jenkins::localstatedir,
        managehome => false,
        system     => true,
    })
  }

  if $jenkins::manage_group {
    ensure_resource('group', $jenkins::group, {
        ensure => present,
        system => true,
    })
  }

  $plugin_dir_params = $jenkins::purge_plugins ? {
    true    => $dir_params + {
      'purge'   => true,
      'recurse' => true,
      'force'   => true,
      'notify'  => Service['jenkins'],
    },
    default => $dir_params,
  }

  if $jenkins::manage_datadirs {
    ensure_resource('file', $jenkins::localstatedir, $dir_params)
    ensure_resource('file', $jenkins::plugin_dir, $plugin_dir_params)
    ensure_resource('file', $jenkins::job_dir, $dir_params)
  }

  # On Debian the service is started by default so it must be configured prior
  # to installation which is why it's configured in this file rather than config.pp
  $config_hash = $jenkins::params::config_hash_defaults + $jenkins::config_hash

  systemd::dropin_file { 'puppet-overrides.conf':
    unit           => 'jenkins.service',
    content        => epp("${module_name}/jenkins-override.epp", { 'environment' => $config_hash, 'dropin_config' => $jenkins::service_override }),
    notify_service => true,
  }
}