diff --git a/.fixtures.yml b/.fixtures.yml index b25e8c459..9ee632dbb 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -5,4 +5,6 @@ fixtures: provision: 'https://github.com/puppetlabs/provision.git' symlinks: stdlib: "#{source_dir}" - test: "#{source_dir}/spec/fixtures/test" \ No newline at end of file + test: "#{source_dir}/spec/fixtures/test" + forge_modules: + concat: "puppetlabs/concat" diff --git a/manifests/manage.pp b/manifests/manage.pp index 82c39bc8d..cb8c3351a 100644 --- a/manifests/manage.pp +++ b/manifests/manage.pp @@ -70,17 +70,17 @@ $create_resources.each |$type, $resources| { $resources.each |$title, $attributes| { case $type { - 'file': { + 'file', 'concat::fragment': { # sanity checks # epp, erb and content are exclusive if 'epp' in $attributes and 'content' in $attributes { - fail("You can not set 'epp' and 'content' for file ${title}") + fail("You can not set 'epp' and 'content' for ${type} ${title}") } if 'erb' in $attributes and 'content' in $attributes { - fail("You can not set 'erb' and 'content' for file ${title}") + fail("You can not set 'erb' and 'content' for ${type} ${title}") } if 'erb' in $attributes and 'epp' in $attributes { - fail("You can not set 'erb' and 'epp' for file ${title}") + fail("You can not set 'erb' and 'epp' for ${type} ${title}") } if 'epp' in $attributes { @@ -91,20 +91,20 @@ $content = epp($attributes['epp']['template']) } } else { - fail("No template configured for epp for file ${title}") + fail("No template configured for epp for ${type} ${title}") } } elsif 'erb' in $attributes { if 'template' in $attributes['erb'] { $content = template($attributes['erb']['template']) } else { - fail("No template configured for erb for file ${title}") + fail("No template configured for erb for ${type} ${title}") } } elsif 'content' in $attributes { $content = $attributes['content'] } else { $content = undef } - file { $title: + $type { $title: * => $attributes - 'erb' - 'epp' - 'content', content => $content, } diff --git a/spec/classes/manage_spec.rb b/spec/classes/manage_spec.rb index ce78ec2f0..db4b6a64e 100644 --- a/spec/classes/manage_spec.rb +++ b/spec/classes/manage_spec.rb @@ -37,6 +37,29 @@ } } }, + 'concat' => { + '/tmp/filename' => { + 'ensure' => 'present', + } + }, + 'concat::fragment' => { + 'rawcontent' => { + 'target' => '/tmp/filename', + 'content' => 'test content', + }, + 'eppcontent' => { + 'target' => '/tmp/filename', + 'epp' => { + 'template' => 'profile/motd.epp' + }, + }, + 'erbcontent' => { + 'target' => '/tmp/filename', + 'erb' => { + 'template' => 'profile/information.erb' + }, + } + }, 'package' => { 'example' => { 'ensure' => 'installed', @@ -58,6 +81,10 @@ it { is_expected.to contain_file('/etc/motd.d/hello').with_content('I say Hi').with_notify('Service[sshd]') } it { is_expected.to contain_file('/etc/motd').with_content(%r{I am an epp template}) } it { is_expected.to contain_file('/etc/information').with_content(%r{I am an erb template}) } + it { is_expected.to contain_concat('/tmp/filename') } + it { is_expected.to contain_concat__fragment('rawcontent').with_content('test content') } + it { is_expected.to contain_concat__fragment('eppcontent').with_content(%r{I am an epp template}) } + it { is_expected.to contain_concat__fragment('erbcontent').with_content(%r{I am an erb template}) } it { is_expected.to contain_package('example').with_ensure('installed').that_subscribes_to(['Service[sshd]', 'File[/etc/motd.d]']) } end end