Puppet Class: influxdb

Defined in:
manifests/init.pp

Summary

Installs, configures, and performs initial setup of InfluxDB 2.x

Overview

Examples:

Basic usage

include influxdb

class {'influxdb':
  initial_org => 'my_org',
  initial_bucket => 'my_bucket',
}

Parameters:

  • manage_repo (Boolean)

    Whether to manage a repository to provide InfluxDB packages. Defaults to true

  • manage_setup (Boolean) (defaults to: true)

    Whether to perform initial setup of InfluxDB. This will create an initial organization, bucket, and admin token. Defaults to true.

  • repo_name (String) (defaults to: 'influxdb2')

    Name of the InfluxDB repository if using $manage_repo. Defaults to influxdb2

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

    Version of InfluxDB to install. Changing this is not recommended.

  • archive_source (Variant[String,Boolean[false]]) (defaults to: 'https://dl.influxdata.com/influxdb/releases/influxdb2-2.1.1-linux-amd64.tar.gz')

    URL containing an InfluxDB archive if not installing from a repository or false to disable installing from source. Defaults to version 2-2.1.1 on amd64 architechture.

  • use_ssl (Boolean) (defaults to: true)

    Whether to use http or https connections. Defaults to true (https).

  • manage_ssl (Boolean) (defaults to: true)

    Whether to manage the SSL bundle for https connections. Defaults to true.

  • ssl_cert_file (String) (defaults to: "/etc/puppetlabs/puppet/ssl/certs/${trusted['certname']}.pem")

    SSL certificate to be used by the influxdb service. Defaults to the agent certificate issued by the Puppet CA for the local machine.

  • ssl_key_file (String) (defaults to: "/etc/puppetlabs/puppet/ssl/private_keys/${trusted['certname']}.pem")

    Private key used in the CSR for the certificate specified by $ssl_cert_file. Defaults to the private key of the local machine for generating a CSR for the Puppet CA

  • ssl_ca_file (String) (defaults to: '/etc/puppetlabs/puppet/ssl/certs/ca.pem')

    CA certificate issued by the CA which signed the certificate specified by $ssl_cert_file. Defaults to the Puppet CA.

  • host (String)

    fqdn of the host running InfluxDB. Defaults to the fqdn of the local machine

  • port (Integer)

    port of the InfluxDB Service. Defaults to 8086

  • initial_org (String)

    Name of the initial organization to use during initial setup. Defaults to puppetlabs

  • initial_bucket (String)

    Name of the initial bucket to use during initial setup. Defaults to puppet_data

  • admin_user (String) (defaults to: 'admin')

    Name of the administrative user to use during initial setup. Defaults to admin

  • admin_pass (Sensitive[String[1]]) (defaults to: Sensitive('puppetlabs'))

    Password for the administrative user in Sensitive format used during initial setup. Defaults to puppetlabs

  • token_file (String) (defaults to: $facts['identity']['user'] ? { 'root' => '/root/.influxdb_token', default => "/home/${facts['identity']['user']}/.influxdb_token")

    File on disk containing an administrative token. This class will write the token generated as part of initial setup to this file. Note that functions or code run in Puppet server will not be able to use this file, so setting $token after setup is recommended.

  • repo_gpg_key_id (String)

    ID of the GPG signing key

  • repo_url (Optional[String]) (defaults to: undef)

    URL of the Package repository

  • repo_gpg_key_url (String)

    URL of the GPG signing key



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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'manifests/init.pp', line 52

class influxdb (
  # Provided by module data
  String  $host,
  Integer $port,
  String  $initial_org,
  String  $initial_bucket,
  String  $repo_gpg_key_id,
  String  $repo_gpg_key_url,
  Boolean $manage_repo,

  Boolean $manage_setup = true,

  Optional[String] $repo_url = undef,
  String  $repo_name = 'influxdb2',
  String  $version = '2.1.1',
  Variant[String,Boolean[false]] $archive_source = 'https://dl.influxdata.com/influxdb/releases/influxdb2-2.1.1-linux-amd64.tar.gz',

  Boolean $use_ssl = true,
  Boolean $manage_ssl = true,
  String  $ssl_cert_file = "/etc/puppetlabs/puppet/ssl/certs/${trusted['certname']}.pem",
  String  $ssl_key_file ="/etc/puppetlabs/puppet/ssl/private_keys/${trusted['certname']}.pem",
  String  $ssl_ca_file ='/etc/puppetlabs/puppet/ssl/certs/ca.pem',

  String  $admin_user = 'admin',
  Sensitive[String[1]] $admin_pass = Sensitive('puppetlabs'),
  String  $token_file = $facts['identity']['user'] ? {
                                      'root'  => '/root/.influxdb_token',
    default => "/home/${facts['identity']['user']}/.influxdb_token" #lint:ignore:parameter_documentation
                                    },
) {
  # We can only manage repos, packages, services, etc on the node we are compiling a catalog for
  unless $host == $facts['networking']['fqdn'] or $host == 'localhost' {
    fail(
      @("MSG")
        Unable to manage InfluxDB installation on host: ${host}.
        Management of repos, packages and services etc is only possible on the local host (${facts['networking']['fqdn']}).
      | MSG
    )
  }

  # If managing SSL, install the package before managing files under /etc/influxdb in order to ensure the directory exists
  $package_before = if $use_ssl and $manage_ssl {
    [
      File['/etc/influxdb/cert.pem', '/etc/influxdb/key.pem', '/etc/influxdb/ca.pem', '/etc/systemd/system/influxdb.service.d'],
      Service['influxdb']
    ]
  }
  else {
    Service['influxdb']
  }

  # If we are managing the repository, set it up and install the package with a require on the repo
  if $manage_repo {
    #TODO: other distros
    case $facts['os']['family'] {
      'RedHat': {
        yumrepo { $repo_name:
          ensure   => 'present',
          descr    => $repo_name,
          name     => $repo_name,
          baseurl  => $repo_url,
          gpgkey   => $repo_gpg_key_url,
          enabled  => '1',
          gpgcheck => '1',
          target   => '/etc/yum.repos.d/influxdb2.repo',
        }
        $package_require = Yumrepo[$repo_name]
      }
      'Debian': {
        include apt
        apt::source { $repo_name:
          ensure   => 'present',
          comment  => 'The InfluxDB2 repository',
          location => $repo_url,
          release  => 'stable',
          repos    => 'main',
          key      => {
            'id'     => $repo_gpg_key_id,
            'source' => $repo_gpg_key_url,
          },
        }
        $package_require = Apt::Source[$repo_name]
      }
      default: {
        notify { 'influxdb_repo_warn':
          message  => "Unable to manage repo on ${facts['os']['family']}, using archive source",
          loglevel => 'warn',
        }
      }
    }

    package {'influxdb2':
      ensure  => $version,
      require => $package_require,
      before  => $package_before,
    }
  }
  # If not managing the repo, install the package from archive source
  elsif $archive_source {
    file { ['/etc/influxdb', '/opt/influxdb', '/etc/influxdb/scripts']:
      ensure => directory,
      owner  => 'root',
      group  => 'root',
    }
    file { '/var/lib/influxdb':
      ensure => directory,
      owner  => 'influxdb',
      group  => 'influxdb',
    }

    $default_dir = $facts['os']['family'] ? {
      'Debian' => '/etc/default',
      default  => '/etc/sysconfig',
    }
    file { '/etc/systemd/system/influxdb.service':
      ensure   => file,
      content  => epp('influxdb/influxdb_service.epp',
      env_file => "${default_dir}/influxdb2"),
    }

    archive { '/tmp/influxdb.tar.gz':
      ensure          => present,
      extract         => true,
      extract_command => 'tar xfz %s --strip-components=1',
      extract_path    => '/opt/influxdb',
      source          => $archive_source,
      cleanup         => true,
      require         => File['/etc/influxdb', '/opt/influxdb'],
      before          => Service['influxdb'],
    }

    group { 'influxdb':
      ensure => present,
    }
    user { 'influxdb':
      ensure => present,
      gid    => 'influxdb',
    }

    file { '/etc/influxdb/scripts/influxd-systemd-start.sh':
      ensure => file,
      source => 'puppet:///modules/influxdb/influxd-systemd-start.sh',
      owner  => 'root',
      group  => 'root',
      mode   => '0775',
      notify => Service['influxdb'],
    }
  }

  # Otherwise, assume we have a source for the package
  else {
    package { 'influxdb2':
      ensure => installed,
      before => $package_before,
    }
  }

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

  if $use_ssl {
    if $manage_ssl {
      file { '/etc/influxdb/cert.pem':
        ensure => file,
        source => "file:///${ssl_cert_file}",
        notify => Service['influxdb'],
      }
      file { '/etc/influxdb/key.pem':
        ensure => file,
        source => "file:///${ssl_key_file}",
        notify => Service['influxdb'],
      }
      file { '/etc/influxdb/ca.pem':
        ensure => file,
        source => "file:///${ssl_ca_file}",
        notify => Service['influxdb'],
      }
    }

    file { '/etc/systemd/system/influxdb.service.d':
      ensure => directory,
      owner  => 'influxdb',
      notify => Service['influxdb'],
    }
    file { '/etc/systemd/system/influxdb.service.d/override.conf':
      ensure  => file,
      #TODO: epp necessary?
      content => epp(
        'influxdb/influxdb_dropin.epp',
        {
          cert => '/etc/influxdb/cert.pem',
          key  => '/etc/influxdb/key.pem',
        }
      ),
      notify  => Service['influxdb'],
    }
  }

  if $manage_setup {
    influxdb_setup { $host:
      ensure     => 'present',
      use_ssl    => $use_ssl,
      token_file => $token_file,
      bucket     => $initial_bucket,
      org        => $initial_org,
      username   => $admin_user,
      password   => $admin_pass,
      require    => Service['influxdb'],
    }
  }
}