Skip to content

Commit 0c0be15

Browse files
committed
Allow removing check config files
Adds a new 'ensure' argument to 'datadog_agent::integration' that can be 'present' (default) or 'absent' (to remove the file).
1 parent 0822e66 commit 0c0be15

2 files changed

Lines changed: 42 additions & 22 deletions

File tree

manifests/integration.pp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
define datadog_agent::integration (
2-
Array $instances,
3-
Optional[Hash] $init_config = undef,
4-
Optional[Array] $logs = undef,
5-
String $integration = $title,
2+
Array $instances = [],
3+
Optional[Hash] $init_config = undef,
4+
Optional[Array] $logs = undef,
5+
String $integration = $title,
6+
Enum['present', 'absent'] $ensure = 'present',
67
){
78

89
include datadog_agent
@@ -20,8 +21,10 @@
2021
$dst = "${datadog_agent::params::legacy_conf_dir}/${integration}.yaml"
2122
}
2223

24+
$file_ensure = $ensure ? { default => file, 'absent' => absent }
25+
2326
file { $dst:
24-
ensure => file,
27+
ensure => $file_ensure,
2528
owner => $datadog_agent::dd_user,
2629
group => $datadog_agent::dd_group,
2730
mode => $datadog_agent::params::permissions_file,

spec/defines/datadog_agent__integration_spec.rb

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,33 @@
1313
end
1414

1515
let(:title) { 'test' }
16-
let(:params) do
17-
{
18-
instances: [
19-
{
20-
one: 'two',
21-
},
22-
],
23-
}
24-
end
16+
gem_spec = Gem.loaded_specs['puppet']
2517

26-
it { is_expected.to compile }
2718
if agent_major_version == 5
2819
it { is_expected.to contain_file(conf_dir.to_s).that_comes_before("File[#{conf_file}]") }
2920
end
30-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{init_config: }) }
31-
gem_spec = Gem.loaded_specs['puppet']
32-
if gem_spec.version >= Gem::Version.new('4.0.0')
33-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
34-
else
35-
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
36-
end
3721
it { is_expected.to contain_file(conf_file.to_s).that_notifies("Service[#{SERVICE_NAME}]") }
3822

23+
context 'with instances' do
24+
let(:params) do
25+
{
26+
instances: [
27+
{
28+
one: 'two',
29+
},
30+
],
31+
}
32+
end
33+
34+
it { is_expected.to compile }
35+
if gem_spec.version >= Gem::Version.new('4.0.0')
36+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{---\ninit_config: \ninstances:\n- one: two\n}) }
37+
else
38+
it { is_expected.to contain_file(conf_file.to_s).with_content(%r{--- \n init_config: \n instances: \n - one: two}) }
39+
end
40+
it { is_expected.to contain_file(conf_file).with_ensure('file') }
41+
end
42+
3943
context 'with logs' do
4044
let(:params) do
4145
{
@@ -48,11 +52,24 @@
4852
}
4953
end
5054

55+
it { is_expected.to compile }
5156
if gem_spec.version >= Gem::Version.new('4.0.0')
5257
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n- one\n- two}) }
5358
else
5459
it { is_expected.to contain_file(conf_file).with_content(%r{logs:\n - one\n - two}) }
5560
end
61+
it { is_expected.to contain_file(conf_file).with_ensure('file') }
62+
end
63+
64+
context 'with ensure absent' do
65+
let(:params) do
66+
{
67+
ensure: 'absent',
68+
}
69+
end
70+
71+
it { is_expected.to compile }
72+
it { is_expected.to contain_file(conf_file).with_ensure('absent') }
5673
end
5774
end
5875
end

0 commit comments

Comments
 (0)