From 3ac955e05dce5fbff4aedaf3e023f25db5cd9afb Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Thu, 30 Aug 2012 10:09:28 +0200 Subject: Allow overriding the target path of a (concat) file and use a custom name. --- manifests/init.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 8741ec7..bd6358e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -94,6 +94,7 @@ # - The final file can be referened as File["/path/to/file"] or # File["concat_/path/to/file"] define concat( + $path = $name, $owner = $::id, $group = $concat::setup::root_group, $mode = '0644', @@ -189,6 +190,7 @@ define concat( } file { $name: + path => $path, ensure => present, alias => "concat_${name}", group => $group, -- cgit v1.2.3 From 1972a9b86b1fcbcef31ad3fedbd825cf08223635 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Thu, 30 Aug 2012 10:10:23 +0200 Subject: Add a second spec test for the name/path combination --- spec/defines/init_spec.rb | 60 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/spec/defines/init_spec.rb b/spec/defines/init_spec.rb index 34fb24b..172929a 100644 --- a/spec/defines/init_spec.rb +++ b/spec/defines/init_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe 'concat' do basedir = '/var/lib/puppet/concat' let(:title) { '/etc/foo.bar' } - let(:facts) { { + let(:facts) { { :concat_basedir => '/var/lib/puppet/concat', :id => 'root', } } @@ -54,4 +54,62 @@ describe 'concat' do end end +describe 'concat' do + + basedir = '/var/lib/puppet/concat' + let(:title) { 'foobar' } + let(:target) { '/etc/foo.bar' } + let(:facts) { { + :concat_basedir => '/var/lib/puppet/concat', + :id => 'root', + } } + let :pre_condition do + 'include concat::setup' + end + + directories = [ + "#{basedir}/foobar", + "#{basedir}/foobar/fragments", + ] + + directories.each do |dirs| + it do + should contain_file(dirs).with({ + 'ensure' => 'directory', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + files = [ + "foobar", + "#{basedir}/foobar/fragments.concat", + ] + + files.each do |file| + it do + should contain_file(file).with({ + 'ensure' => 'present', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + it do + should contain_exec("concat_foobar").with_command( + "#{basedir}/bin/concatfragments.sh " + + "-o #{basedir}/foobar/fragments.concat.out " + + "-d #{basedir}/foobar " + ) + end + + +end + # vim:sw=2:ts=2:expandtab:textwidth=79 -- cgit v1.2.3 From 6a0c1f9a393ff293d4c21e11851001c86ba82ef4 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Thu, 30 Aug 2012 11:06:58 +0200 Subject: Document the path parameter and provide a small use case. --- manifests/init.pp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index bd6358e..8398e92 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -30,6 +30,30 @@ # will have an number prefix of 10, you can use the order option # to control that and thus control the order the final file gets built in. # +# You can also specify a path and use a different name for your resources: +# +# # You can make this something dynamic, based on whatever parameters your +# # module/class for example. +# $vhost_file = '/etc/httpd/vhosts/01-my-vhost.conf' +# +# concat{'apache-vhost-myvhost': +# path => $vhost_file, +# } +# +# # We don't care where the file is located, just what to put in it. +# concat::fragment {'apache-vhost-myvhost-main': +# target => 'apache-vhost-myvhost', +# content => '', +# order => 01, +# } +# +# concat::fragment {'apache-vhost-myvhost-close': +# target => 'apache-vhost-myvhost', +# content => '', +# order => 99, +# } +# +# # SETUP: # The class concat::setup uses the fact concat_basedir to define the variable # $concatdir, where all the temporary files and fragments will be @@ -66,6 +90,10 @@ # Sets up so that you can use fragments to build a final config file, # # OPTIONS: +# - path The path to the final file. Use this in case you want to +# differentiate between the name of a resource and the file path. +# Note: Use the name you provided in the target of your +# fragments. # - mode The mode of the final file # - owner Who will own the file # - group Who will own the file -- cgit v1.2.3