]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/concat/lib/puppet/type/concat_fragment.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / concat / lib / puppet / type / concat_fragment.rb
1 Puppet::Type.newtype(:concat_fragment) do
2   @doc = "Create a concat fragment to be used by concat.
3     the `concat_fragment` type creates a file fragment to be collected by concat based on the tag.
4     The example is based on exported resources.
5
6     Example:
7     @@concat_fragment { \"uniqe_name_${::fqdn}\":
8       tag => 'unique_name',
9       order => 10, # Optional. Default to 10
10       content => 'some content' # OR
11       content => template('template.erb') # OR
12       source  => 'puppet:///path/to/file'
13     }
14   "
15
16   newparam(:name, :namevar => true) do
17     desc "Unique name"
18   end
19
20   newparam(:content) do
21     desc "Content"
22   end
23
24   newparam(:source) do
25     desc "Source"
26   end
27
28   newparam(:order) do
29     desc "Order"
30     defaultto '10'
31     validate do |val|
32       fail Puppet::ParseError, '$order is not a string or integer.' if !(val.is_a? String or val.is_a? Integer)
33       fail Puppet::ParseError, "Order cannot contain '/', ':', or '\n'." if val.to_s =~ /[:\n\/]/
34     end
35   end
36
37   newparam(:tag) do
38     desc "Tag name to be used by concat to collect all concat_fragments by tag name"
39   end
40
41   validate do
42     # Check if either source or content is set. raise error if none is set
43     fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil?
44
45     # Check if both are set, if so rais error
46     fail Puppet::ParseError, "Can't use 'source' and 'content' at the same time" if !self[:source].nil? && !self[:content].nil?
47   end
48 end