From 14a957b133b3839e32cad2f27a817033661f16c5 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 2 Jun 2023 21:34:45 +0200 Subject: [PATCH] use to_toml instead of toml gem --- .sync.yml | 6 ------ Gemfile | 2 -- README.md | 4 +++- manifests/aggregator.pp | 2 +- manifests/config.pp | 18 ++++++++++++++++- manifests/input.pp | 2 +- manifests/output.pp | 2 +- manifests/processor.pp | 2 +- metadata.json | 2 +- spec/spec_helper_acceptance.rb | 4 +--- templates/telegraf.conf.erb | 35 ---------------------------------- 11 files changed, 26 insertions(+), 53 deletions(-) delete mode 100644 templates/telegraf.conf.erb diff --git a/.sync.yml b/.sync.yml index fa40e42..5f7b1bf 100644 --- a/.sync.yml +++ b/.sync.yml @@ -1,10 +1,4 @@ --- -Gemfile: - optional: - ':test': - - gem: 'toml-rb' - ':system_tests': - - gem: 'toml-rb' spec/spec_helper.rb: hiera_config: "'spec/hiera.yaml'" .puppet-lint.rc: diff --git a/Gemfile b/Gemfile index ecc18cb..98a04cf 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,6 @@ group :test do gem 'coveralls', :require => false gem 'simplecov-console', :require => false gem 'puppet_metadata', '~> 3.0', :require => false - gem 'toml-rb', :require => false end group :development do @@ -18,7 +17,6 @@ end group :system_tests do gem 'voxpupuli-acceptance', '~> 2.0', :require => false - gem 'toml-rb', :require => false end group :release do diff --git a/README.md b/README.md index 10d1de9..ecbfec5 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ This module has the following dependencies: for TLS-enabled repos in place. This can be achieved by installing the `apt-transport-https` package. -This module **requires** the [toml-rb](https://github.com/eMancu/toml-rb) gem. Either install the gem using puppet's native gem provider, [puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/puppetserver_gem), [pe_gem](https://forge.puppetlabs.com/puppetlabs/pe_gem), [pe_puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/pe_puppetserver_gem), or manually using one of the following methods: +**Up to version v4.3.1** this module **requires** the [toml-rb](https://github.com/eMancu/toml-rb) gem. Either install the gem using puppet's native gem provider, [puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/puppetserver_gem), [pe_gem](https://forge.puppetlabs.com/puppetlabs/pe_gem), [pe_puppetserver_gem](https://forge.puppetlabs.com/puppetlabs/pe_puppetserver_gem), or manually using one of the following methods: ``` # apply or puppet-master gem install toml-rb @@ -43,6 +43,8 @@ This module **requires** the [toml-rb](https://github.com/eMancu/toml-rb) gem. E /opt/puppet/bin/puppetserver gem install toml-rb ``` +The toml-rb gem got replaced with `stdlib::to_toml`. This requires puppetlabs/stdlib 9. + In addition, for Windows, the following dependencies must be met: * Chocolatey installed diff --git a/manifests/aggregator.pp b/manifests/aggregator.pp index ca9a1d8..eb48e92 100644 --- a/manifests/aggregator.pp +++ b/manifests/aggregator.pp @@ -19,7 +19,7 @@ file { "${telegraf::config_folder}/${name}.conf": ensure => $_ensure, - content => inline_template("<%= require 'toml-rb'; TomlRB.dump({'aggregators'=>{'${plugin_type}'=>@options}}) %>"), + content => to_toml({ 'aggregators'=> { $plugin_type=> $options } }), require => Class['telegraf::config'], notify => Class['telegraf::service'], } diff --git a/manifests/config.pp b/manifests/config.pp index 46b6fca..e9fbcbb 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -5,9 +5,25 @@ class telegraf::config inherits telegraf { assert_private() + $agent = { + 'hostname' => $telegraf::hostname, + 'omit_hostname' => $telegraf::omit_hostname, + 'interval' => $telegraf::interval, + 'round_interval' => $telegraf::round_interval, + 'metric_batch_size' => $telegraf::metric_batch_size, + 'metric_buffer_limit' => $telegraf::metric_buffer_limit, + 'collection_jitter' => $telegraf::collection_jitter, + 'flush_interval' => $telegraf::flush_interval, + 'flush_jitter' => $telegraf::flush_jitter, + 'precision' => $telegraf::precision, + 'logfile' => $telegraf::logfile, + 'debug' => $telegraf::debug, + 'quiet' => $telegraf::quiet, + } + $config = to_toml({ 'global_tags' => $telegraf::global_tags, 'agent' => $agent, 'outputs' => $telegraf::outputs, 'inputs' => $telegraf::inputs }) file { $telegraf::config_file: ensure => $telegraf::ensure_file, - content => template('telegraf/telegraf.conf.erb'), + content => $config, owner => $telegraf::config_file_owner, group => $telegraf::config_file_group, mode => $telegraf::config_file_mode, diff --git a/manifests/input.pp b/manifests/input.pp index 7897c67..0cecda6 100644 --- a/manifests/input.pp +++ b/manifests/input.pp @@ -19,7 +19,7 @@ file { "${telegraf::config_folder}/${name}.conf": ensure => $_ensure, - content => inline_template("<%= require 'toml-rb'; TomlRB.dump({'inputs'=>{'${plugin_type}'=>@options}}) %>"), + content => to_toml({ 'inputs'=> { $plugin_type=> $options } }), require => Class['telegraf::config'], notify => Class['telegraf::service'], } diff --git a/manifests/output.pp b/manifests/output.pp index 8ce9c27..a4ffdbf 100644 --- a/manifests/output.pp +++ b/manifests/output.pp @@ -19,7 +19,7 @@ file { "${telegraf::config_folder}/${name}.conf": ensure => $_ensure, - content => inline_template("<%= require 'toml-rb'; TomlRB.dump({'outputs'=>{'${plugin_type}'=>@options}}) %>"), + content => to_toml({ 'outputs'=> { $plugin_type=> $options } }), require => Class['telegraf::config'], notify => Class['telegraf::service'], } diff --git a/manifests/processor.pp b/manifests/processor.pp index 8c3e63b..5476803 100644 --- a/manifests/processor.pp +++ b/manifests/processor.pp @@ -20,7 +20,7 @@ file { "${telegraf::config_folder}/${name}.conf": ensure => $_ensure, - content => inline_template("<%= require 'toml-rb'; TomlRB.dump({'processors'=>{'${plugin_type}'=>@options}}) %>"), + content => to_toml({ 'processors'=> { $plugin_type=> $options } }), require => Class['telegraf::config'], notify => Class['telegraf::service'], } diff --git a/metadata.json b/metadata.json index cbe955e..b6d7614 100644 --- a/metadata.json +++ b/metadata.json @@ -83,7 +83,7 @@ "dependencies": [ { "name": "puppetlabs-stdlib", - "version_requirement": ">= 5.0.0 < 9.0.0" + "version_requirement": ">= 9.0.0 < 10.0.0" }, { "name": "puppetlabs-apt", diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index bd75635..6855881 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -2,6 +2,4 @@ require 'voxpupuli/acceptance/spec_helper_acceptance' -configure_beaker do |host| - on host, '/opt/puppetlabs/puppet/bin/gem install toml-rb' -end +configure_beaker diff --git a/templates/telegraf.conf.erb b/templates/telegraf.conf.erb deleted file mode 100644 index 9129234..0000000 --- a/templates/telegraf.conf.erb +++ /dev/null @@ -1,35 +0,0 @@ -# Telegraf Configuration -# -# THIS FILE IS MANAGED BY PUPPET -# -<% if @global_tags -%> -[global_tags] -<% @global_tags.sort.each do |key, value| -%> - <%= key %> = "<%= value %>" -<% end -%> -<% end -%> - -[agent] - hostname = "<%= @hostname %>" - omit_hostname = <%= @omit_hostname %> - interval = "<%= @interval %>" - round_interval = <%= @round_interval %> - metric_batch_size = <%= @metric_batch_size %> - metric_buffer_limit = <%= @metric_buffer_limit %> - collection_jitter = "<%= @collection_jitter %>" - flush_interval = "<%= @flush_interval %>" - flush_jitter = "<%= @flush_jitter %>" - precision = "<%= @precision %>" - logfile = "<%= @logfile %>" - debug = <%= @debug %> - quiet = <%= @quiet %> - -# -# OUTPUTS: -# -<%= require 'toml-rb'; TomlRB.dump({'outputs'=>@outputs}) %> - -# -# INPUTS: -# -<%= require 'toml-rb'; TomlRB.dump({'inputs'=>@inputs}) %>