Puppet Class: telegraf::install

Defined in:
manifests/install.pp

Overview

Class: telegraf::install

Conditionally handle InfluxData’s official repos and install the necessary Telegraf package.



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

class telegraf::install {
  assert_private()

  case $facts['os']['family'] {
    'Darwin': {
      if $telegraf::manage_archive {
        if $telegraf::manage_user {
          group { $telegraf::config_file_group:
            ensure => present,
          }

          user { $telegraf::config_file_owner:
            ensure => present,
            gid    => $telegraf::config_file_group,
          }
        }

        $install_dir_deps = [
          '/usr/local/bin',
          '/usr/local/etc',
          '/usr/local/opt',
          '/usr/local/var',
          '/usr/local/var/log',
        ]

        file { $install_dir_deps:
          ensure => directory,
        }

        file { "${telegraf::archive_install_dir}-${telegraf::archive_version}":
          ensure  => directory,
          owner   => $telegraf::config_file_owner,
          group   => $telegraf::config_file_group,
          require => File[$install_dir_deps],
        }

        archive { "/tmp/telegraf-${telegraf::archive_version}.tar.gz":
          ensure          => present,
          extract         => true,
          extract_path    => "${telegraf::archive_install_dir}-${telegraf::archive_version}",
          extract_command => 'tar xfz %s --strip-components=2',
          source          => "https://dl.influxdata.com/telegraf/releases/telegraf-${telegraf::archive_version}_darwin_amd64.tar.gz",
          creates         => "${telegraf::archive_install_dir}-${$telegraf::archive_version}/usr/bin/telegraf",
          user            => $telegraf::config_file_owner,
          group           => $telegraf::config_file_group,
          cleanup         => true,
          require         => File["${telegraf::archive_install_dir}-${telegraf::archive_version}"],
        }

        file {
          default:
            ensure  => link,
            require => Archive["/tmp/telegraf-${telegraf::archive_version}.tar.gz"],
            ;
          '/usr/local/bin/telegraf':
            target  => "${telegraf::archive_install_dir}-${telegraf::archive_version}/usr/bin/telegraf",
            ;
          '/usr/local/etc/telegraf':
            target  => "${telegraf::archive_install_dir}-${telegraf::archive_version}/etc/telegraf",
            ;
          '/usr/local/var/log/telegraf':
            target  => "${telegraf::archive_install_dir}-${telegraf::archive_version}/var/log/telegraf",
            ;
        }

        file { '/Library/LaunchDaemons/telegraf.plist':
          ensure  => file,
          content => epp('telegraf/telegraf.plist.epp', {
              'config_file_owner' => $telegraf::config_file_owner,
              'config_file_group' => $telegraf::config_file_group,
          }),
        }
      }
      elsif $telegraf::manage_repo {
        notify { 'telegraf repo warn':
          message  => "Installing from repo on ${facts['os']['name']} is not supported",
          loglevel => 'warning',
        }
      }
    }
    'Debian': {
      if $telegraf::manage_repo {
        apt::source { 'influxdata':
          ensure   => $telegraf::ensure_status,
          comment  => 'Mirror for InfluxData packages',
          location => "${telegraf::repo_location}debian",
          release  => 'stable',
          repos    => 'main',
          key      => {
            'id'     => '9D539D90D3328DC7D6C8D3B9D8FF8E1F7DF8B07E',
            'source' => "${telegraf::repo_location}influxdata-archive_compat.key",
          },
        }
        Class['apt::update'] -> Package[$telegraf::package_name]
      }
      elsif $telegraf::manage_archive {
        notify { 'telegraf archive warn':
          message  => "Installing from archive on ${facts['os']['name']} is not supported",
          loglevel => 'warning',
        }
      }
    }
    'RedHat': {
      if $telegraf::manage_repo {
        if $facts['os']['name'] == 'Amazon' {
          $_baseurl = "https://repos.influxdata.com/rhel/6/\$basearch/${telegraf::repo_type}"
        } else {
          $_baseurl = "https://repos.influxdata.com/rhel/\$releasever/\$basearch/${telegraf::repo_type}"
        }
        yumrepo { 'influxdata':
          ensure   => $telegraf::ensure_status,
          name     => 'influxdata',
          descr    => "InfluxData Repository - ${facts['os']['name']} \$releasever",
          enabled  => 1,
          baseurl  => $_baseurl,
          gpgkey   => "${telegraf::repo_location}influxdata-archive_compat.key",
          gpgcheck => 1,
        }
        Yumrepo['influxdata'] -> Package[$telegraf::package_name]
      }
      elsif $telegraf::manage_archive {
        file { $telegraf::archive_install_dir:
          ensure => directory,
        }
        archive { '/tmp/telegraf.tar.gz':
          ensure          => present,
          extract         => true,
          extract_command => 'tar xfz %s --strip-components=2',
          extract_path    => $telegraf::archive_install_dir,
          creates         => "${telegraf::archive_install_dir}/usr/bin/telegraf",
          source          => $telegraf::archive_location,
          cleanup         => true,
          require         => File[$telegraf::archive_install_dir],
        }
        file { '/etc/telegraf':
          ensure => directory,
        }
        if $telegraf::manage_user {
          group { $telegraf::config_file_group:
            ensure => present,
          }
          user { $telegraf::config_file_owner:
            ensure => present,
            gid    => $telegraf::config_file_group,
          }
        }
        file { '/etc/systemd/system/telegraf.service':
          ensure => file,
          source => 'puppet:///modules/telegraf/telegraf.service',
        }
        file { '/var/log/telegraf':
          ensure => directory,
          owner  => $telegraf::config_file_owner,
          group  => $telegraf::config_file_group,
        }
      }
    }
    'Suse': {
      if $telegraf::manage_archive {
        file { $telegraf::archive_install_dir:
          ensure => directory,
        }
        archive { '/tmp/telegraf.tar.gz':
          ensure          => present,
          extract         => true,
          extract_command => 'tar xfz %s --strip-components=2',
          extract_path    => $telegraf::archive_install_dir,
          source          => $telegraf::archive_location,
          creates         => "${telegraf::archive_install_dir}/usr/bin/telegraf",
          cleanup         => true,
          require         => File[$telegraf::archive_install_dir],
        }
        file { '/etc/telegraf':
          ensure => directory,
        }
        if $telegraf::manage_user {
          group { $telegraf::config_file_group:
            ensure => present,
          }
          user { $telegraf::config_file_owner:
            ensure => present,
            gid    => $telegraf::config_file_group,
          }
        }
        file { '/etc/systemd/system/telegraf.service':
          ensure => file,
          source => 'puppet:///modules/telegraf/telegraf.service',
        }
        file { '/var/log/telegraf':
          ensure => directory,
          owner  => $telegraf::config_file_owner,
          group  => $telegraf::config_file_group,
        }
      }
      elsif $telegraf::manage_repo {
        notify { 'telegraf repo warn':
          message  => "Installing from repo on ${facts['os']['name']} is not supported",
          loglevel => 'warning',
        }
      }
    }
    'windows': {
      # repo is not applicable to windows
    }
    'FreeBSD': {
      # repo is not applicable to windows
    }
    default: {
      fail('Only RedHat, CentOS, OracleLinux, Debian, Ubuntu, Darwin, FreeBSD and Windows repositories and Suse archives are supported at this time')
    }
  }

  if $facts['os']['family'] == 'windows' {
    # required to install telegraf on windows
    require chocolatey

    # package install
    package { $telegraf::package_name:
      ensure          => $telegraf::ensure,
      provider        => chocolatey,
      source          => $telegraf::windows_package_url,
      install_options => $telegraf::install_options,
    }
  } else {
    if ! $telegraf::manage_archive {
      stdlib::ensure_packages([$telegraf::package_name],
        {
          ensure          => $telegraf::ensure,
          install_options => $telegraf::install_options,
        }
      )
    }
  }
}