Puppet Class: etcd

Defined in:
manifests/init.pp

Summary

Manage etcd

Overview

Examples:

include etcd

Parameters:

  • version (String) (defaults to: '3.4.7')

    Version of etcd to install Not used if download_url is defined.

  • base_url (Stdlib::HTTPUrl) (defaults to: 'https://github.com/etcd-io/etcd/releases/download')

    Base URL of where to download etcd binaries. Not used if download_url is defined.

  • os (String[1]) (defaults to: downcase($facts['kernel']))

    The GOOS to install Not used if download_url is defined.

  • arch (String[1]) (defaults to: $facts['os']['architecture'])

    The GOARCH to install Not used if download_url is defined.

  • download_url (Optional[Stdlib::HTTPUrl]) (defaults to: undef)

    Alternative location to download etcd binaries

  • download_dir (Stdlib::Absolutepath) (defaults to: '/tmp')

    The directory of where to download etcd

  • extract_dir (Stdlib::Absolutepath) (defaults to: '/opt')

    The directory where to extract etcd

  • bin_dir (Stdlib::Absolutepath) (defaults to: '/usr/bin')

    The path to bin directory for etcd and etcdctl symlinks

  • manage_user (Boolean) (defaults to: true)

    Boolean that determines if etcd user is managed

  • manage_group (Boolean) (defaults to: true)

    Boolean that determines if etcd group is managed

  • user (String[1]) (defaults to: 'etcd')

    The etcd user

  • user_uid (Optional[Integer]) (defaults to: undef)

    The etcd user UID

  • group (String[1]) (defaults to: 'etcd')

    The etcd group

  • group_gid (Optional[Integer]) (defaults to: undef)

    The etcd group GID

  • config_path (Stdlib::Absolutepath) (defaults to: '/etc/etcd.yaml')

    The path to etcd YAML configuration

  • config (Hash) (defaults to: { 'data-dir' => '/var/lib/etcd' })

    The config values to pass to etcd

  • max_open_files (Integer) (defaults to: 40000)

    The value for systemd LimitNOFILE unit option



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
182
183
184
185
186
187
# File 'manifests/init.pp', line 44

class etcd (
  String $version = '3.4.7',
  Stdlib::HTTPUrl $base_url = 'https://github.com/etcd-io/etcd/releases/download',
  String[1] $os = downcase($facts['kernel']),
  String[1] $arch = $facts['os']['architecture'],
  Optional[Stdlib::HTTPUrl] $download_url = undef,
  Stdlib::Absolutepath $download_dir = '/tmp',
  Stdlib::Absolutepath $extract_dir = '/opt',
  Stdlib::Absolutepath $bin_dir = '/usr/bin',
  Boolean $manage_user = true,
  Boolean $manage_group = true,
  String[1] $user = 'etcd',
  Optional[Integer] $user_uid = undef,
  String[1] $group = 'etcd',
  Optional[Integer] $group_gid = undef,
  Stdlib::Absolutepath $config_path = '/etc/etcd.yaml',
  Hash $config = { 'data-dir' => '/var/lib/etcd' },
  Integer $max_open_files = 40000,
) {
  if $os != 'linux' {
    fail("Module etcd only supports Linux, not ${os}")
  }
  if $facts['service_provider'] != 'systemd' {
    fail('Module etcd only supported on systems using systemd')
  }
  if ! $config['data-dir'] {
    fail('Module etcd requires data-dir be specified in config Hash')
  }

  case $arch {
    'x86_64', 'amd64': { $real_arch = 'amd64' }
    'aarch64':         { $real_arch = 'arm64' }
    default:           { $real_arch = $arch }
  }

  $_download_url = pick($download_url, "${base_url}/v${version}/etcd-v${version}-${os}-${real_arch}.tar.gz")
  $install_dir = "${extract_dir}/etcd-${version}"

  file { $install_dir:
    ensure => 'directory',
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  archive { "${download_dir}/etcd.tar.gz":
    source          => $_download_url,
    extract         => true,
    extract_path    => $install_dir,
    extract_command => 'tar xfz %s --strip-components=1',
    creates         => "${install_dir}/etcd",
    cleanup         => true,
    user            => 'root',
    group           => 'root',
    require         => File[$install_dir],
    before          => [
      File['etcd'],
      File['etcdctl'],
    ],
  }

  file { 'etcd':
    ensure => 'link',
    path   => "${bin_dir}/etcd",
    target => "${install_dir}/etcd",
    notify => Service['etcd'],
  }
  file { 'etcdctl':
    ensure => 'link',
    path   => "${bin_dir}/etcdctl",
    target => "${install_dir}/etcdctl",
  }

  if $manage_user {
    user { 'etcd':
      ensure     => 'present',
      name       => $user,
      forcelocal => true,
      shell      => '/bin/false',
      gid        => $group,
      uid        => $user_uid,
      home       => $config['data-dir'],
      managehome => false,
      system     => true,
      before     => Service['etcd'],
    }
  }
  if $manage_group {
    group { 'etcd':
      ensure     => 'present',
      name       => $group,
      forcelocal => true,
      gid        => $group_gid,
      system     => true,
      before     => Service['etcd'],
    }
  }

  file { 'etcd.yaml':
    ensure  => 'file',
    path    => $config_path,
    owner   => $user,
    group   => $group,
    mode    => '0600',
    content => to_yaml($config),
    notify  => Service['etcd'],
  }

  file { 'etcd-data-dir':
    ensure => 'directory',
    path   => $config['data-dir'],
    owner  => $user,
    group  => $group,
    mode   => '0700',
    notify => Service['etcd'],
  }

  if $config['wal-dir'] {
    file { 'etcd-wal-dir':
      ensure => 'directory',
      path   => $config['wal-dir'],
      owner  => $user,
      group  => $group,
      mode   => '0700',
      notify => Service['etcd'],
    }
  }

  systemd::unit_file { 'etcd.service':
    content => template('etcd/etcd.service.erb'),
    notify  => Service['etcd'],
  }

  if versioncmp($facts['puppetversion'],'6.1.0') < 0 {
    # Puppet 5 does not execute 'systemctl daemon-reload' automatically (https://tickets.puppetlabs.com/browse/PUP-3483)
    # and camptocamp/systemd only creates this relationship when managing the service
    Class['systemd::systemctl::daemon_reload'] -> Service['etcd']
  }

  service { 'etcd':
    ensure => 'running',
    enable => true,
  }
}