Puppet Class: consul::install

Defined in:
manifests/install.pp

Summary

Installs consul based on the parameters from init

Overview



5
6
7
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'manifests/install.pp', line 5

class consul::install {
  assert_private()
  $real_data_dir = pick($consul::data_dir, $consul::config_hash[data_dir], $consul::config_defaults[data_dir])

  if $consul::manage_data_dir {
    file { $real_data_dir:
      ensure => 'directory',
      owner  => $consul::user_real,
      group  => $consul::group_real,
      mode   => $consul::data_dir_mode,
    }
  }

  # only notify if we are installing a new version (work around for switching
  # to archive module)
  if $facts['consul_version'] != $consul::version {
    $do_notify_service = Class['consul::run_service']
  } else {
    $do_notify_service = undef
  }

  case $consul::install_method {
    'docker': {
      # Do nothing as docker will install when run
    }
    'url': {
      $install_path = pick($consul::archive_path, "${real_data_dir}/archives")

      include archive

      file { [$install_path, "${install_path}/consul-${consul::version}"]:
        ensure => directory,
        owner  => $consul::binary_owner,
        group  => $consul::binary_group,
        mode   => $consul::binary_mode,
      }

      archive { "${install_path}/consul-${consul::version}.${consul::download_extension}":
        ensure       => present,
        source       => $consul::real_download_url,
        proxy_server => $consul::proxy_server,
        extract      => true,
        extract_path => "${install_path}/consul-${consul::version}",
        creates      => "${install_path}/consul-${consul::version}/${consul::binary_name}",
        require      => File["${install_path}/consul-${consul::version}"],
      }

      file { "${install_path}/consul-${consul::version}/${consul::binary_name}":
        owner   => $consul::binary_owner,
        group   => $consul::binary_group,
        mode    => $consul::binary_mode,
        require => Archive["${install_path}/consul-${consul::version}.${consul::download_extension}"],
      }

      file { "${consul::bin_dir}/${consul::binary_name}":
        ensure  => link,
        notify  => $do_notify_service,
        target  => "${install_path}/consul-${consul::version}/${consul::binary_name}",
        require => File["${install_path}/consul-${consul::version}/${consul::binary_name}"],
      }
    }
    'package': {
      if $consul::manage_repo {
        include hashi_stack::repo
        if $facts['os']['family'] == 'Debian' {
          Exec['apt_update'] -> Package[$consul::package_name]
        } else {
          Class['hashi_stack::repo'] -> Package[$consul::package_name]
        }
      }
      package { $consul::package_name:
        ensure => $consul::package_ensure,
        notify => $do_notify_service,
      }

      if $consul::manage_user {
        User[$consul::user_real] -> Package[$consul::package_name]
      }

      if $consul::data_dir and $consul::manage_data_dir {
        Package[$consul::package_name] -> File[$real_data_dir]
      }
    }
    'none': {}
    default: {
      fail("The provided install method ${consul::install_method} is invalid")
    }
  }

  if ($consul::manage_user) and ($consul::install_method != 'docker' ) {
    # If the consul user already exists and this tries to change its home
    # location the puppet run will fail if the consul service is currently
    # running. This is a workaround for
    # https://github.com/solarkennedy/puppet-consul/issues/559
    $consul_user_home = $consul::manage_user_home_location ? {
      true  => $real_data_dir,
      false => undef,
    }

    user { $consul::user_real:
      ensure  => 'present',
      system  => true,
      groups  => $consul::extra_groups,
      shell   => $consul::shell,
      home    => $consul_user_home,
      uid     => $consul::uid,
      comment => $consul::comment,
    }

    if ($consul::manage_group) and ($consul::install_method != 'docker' ) {
      Group[$consul::group_real] -> User[$consul::user_real]
    }
  }
  if ($consul::manage_group) and ($consul::install_method != 'docker' ) {
    group { $consul::group_real:
      ensure => 'present',
      system => true,
      gid    => $consul::gid,
    }
  }
}