Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for purging unmanaged config fragments #43

Merged
merged 2 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I was wondering when some Puppet 4 syntax would finally creep in ;)

This is great, but you'll need to update the module's metadata to state this as a requirement. I'll then call it out as a breaking change in version 2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I didn't even think about that when I was writing it. I'm happy to modify it so that it'll work on older Puppets.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, probably a good idea to maintain compatibility with older versions of Puppet for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I've repeated the parameters on each file than using File {} to avoid scope-related weirdness, however unlikely.

$::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