Skip to content

Commit

Permalink
Add support for purging unmanaged config fragments (#43)
Browse files Browse the repository at this point in the history
* Add support for purging unmanaged config files

This currently defaults to disabled to ease migration from previous
versions.

* Use Puppet3-compatible resource syntax

This doesn't rely on File {} defaults to avoid potential scope
weirdness, however unlikely.
  • Loading branch information
cosmopetrich authored and yankcrime committed Jan 18, 2017
1 parent d11bfa2 commit f617cd5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
28 changes: 20 additions & 8 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,26 @@

assert_private()

file { $::telegraf::config_file:
ensure => file,
content => template('telegraf/telegraf.conf.erb'),
mode => '0640',
owner => 'telegraf',
group => 'telegraf',
notify => Class['::telegraf::service'],
require => Class['::telegraf::install'],
file {
$::telegraf::config_file:
ensure => file,
content => template('telegraf/telegraf.conf.erb'),
owner => 'telegraf',
group => 'telegraf',
mode => '0640',
notify => Class['::telegraf::service'],
require => Class['::telegraf::install'],
;
$::telegraf::config_fragment_dir:
ensure => directory,
owner => 'telegraf',
group => 'telegraf',
mode => '0750',
purge => $::telegraf::purge_config_fragments,
recurse => true,
notify => Class['::telegraf::service'],
require => Class['::telegraf::install'],
;
}

}
10 changes: 10 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# [*config_file*]
# String. Path to the configuration file.
#
# [*config_fragment_dir*]
# String. Path to the configuration fragment directory.
#
# [*hostname*]
# String. Override default hostname used to identify this agent.
#
Expand Down Expand Up @@ -60,12 +63,16 @@
# [*manage_repo*]
# Boolean. Whether or not to manage InfluxData's repo.
#
# [*purge_config_fragments*]
# Boolean. Whether unmanaged configuration fragments should be removed.
#
# [*repo_type*]
# String. Which repo (stable, unstable, nightly) to use
#
class telegraf (
$ensure = $telegraf::params::ensure,
$config_file = $telegraf::params::config_file,
$config_fragment_dir = $telegraf::params::config_fragment_dir,
$hostname = $telegraf::params::hostname,
$omit_hostname = $telegraf::params::omit_hostname,
$interval = $telegraf::params::interval,
Expand All @@ -82,12 +89,14 @@
$global_tags = $telegraf::params::global_tags,
$manage_service = $telegraf::params::manage_service,
$manage_repo = $telegraf::params::manage_repo,
$purge_config_fragments = $telegraf::params::purge_config_fragments,
$repo_type = $telegraf::params::repo_type,
) inherits ::telegraf::params
{

validate_string($ensure)
validate_string($config_file)
validate_absolute_path($config_fragment_dir)
validate_string($hostname)
validate_bool($omit_hostname)
validate_string($interval)
Expand All @@ -104,6 +113,7 @@
validate_hash($global_tags)
validate_bool($manage_service)
validate_bool($manage_repo)
validate_bool($purge_config_fragments)
validate_string($repo_type)

# currently the only way how to obtain merged hashes
Expand Down
2 changes: 1 addition & 1 deletion manifests/input.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

Class['::telegraf::config']
->
file {"/etc/telegraf/telegraf.d/${name}.conf":
file {"${telegraf::config_fragment_dir}/${name}.conf":
content => template('telegraf/input.conf.erb')
}
~>
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$ensure = 'present'
$config_file = '/etc/telegraf/telegraf.conf'
$config_fragment_dir = '/etc/telegraf/telegraf.d'
$hostname = $::hostname
$omit_hostname = false
$interval = '10s'
Expand All @@ -20,6 +21,7 @@
$global_tags = {}
$manage_service = true
$manage_repo = true
$purge_config_fragments = false
$repo_type = 'stable'

$outputs = {
Expand Down
3 changes: 3 additions & 0 deletions spec/classes/telegraf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
)
}
it { should contain_file('/etc/telegraf/telegraf.conf') }
it { should contain_file('/etc/telegraf/telegraf.d')
.with_purge(false)
}
it { should contain_package('telegraf') }
it { should contain_service('telegraf') }
it { should contain_yumrepo('influxdata')
Expand Down

0 comments on commit f617cd5

Please sign in to comment.