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

class telegraf::install {
  assert_private()

  if $telegraf::manage_repo {
    case $facts['os']['family'] {
      'Debian': {
        if $facts['os']['name'] == 'Raspbian' {
          $distro = $facts['os']['family'].downcase
        } else {
          $distro = $facts['os']['name'].downcase
        }
        if $facts.dig('os','distro','codename') {
          $release = $facts['os']['distro']['codename']
        } else {
          $release = $facts['os']['lsb']['codename']
        }
        apt::source { 'influxdata':
          comment  => 'Mirror for InfluxData packages',
          location => "${telegraf::repo_location}${distro}",
          release  => $release,
          repos    => $telegraf::repo_type,
          key      => {
            'id'     => '05CE15085FC09D18E99EFB22684A14CF2582E0C5',
            'source' => "${telegraf::repo_location}influxdb.key",
          },
        }
        Class['apt::update'] -> Package[$telegraf::package_name]
      }
      'RedHat': {
        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':
          name     => 'influxdata',
          descr    => "InfluxData Repository - ${facts['os']['name']} \$releasever",
          enabled  => 1,
          baseurl  => $_baseurl,
          gpgkey   => "${telegraf::repo_location}influxdb.key",
          gpgcheck => 1,
        }
        Yumrepo['influxdata'] -> Package[$telegraf::package_name]
      }
      'windows': {
        # repo is not applicable to windows
      }
      default: {
        fail('Only RedHat, CentOS, OracleLinux, Debian, Ubuntu and Windows repoisitories are supported at this time')
      }
    }
  }

  if $telegraf::manage_archive {
    case $facts['os']['family'] {
      'Suse': {
        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,
          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,
        }
      }
      default: {
        fail('Only 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 {
      ensure_packages([$telegraf::package_name], { ensure => $telegraf::ensure, install_options => $telegraf::install_options })
    }
  }
}