Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/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(:target) do
21     desc "Target"
22   end
23
24   newparam(:content) do
25     desc "Content"
26   end
27
28   newparam(:source) do
29     desc "Source"
30   end
31
32   newparam(:order) do
33     desc "Order"
34     defaultto '10'
35     validate do |val|
36       fail Puppet::ParseError, '$order is not a string or integer.' if !(val.is_a? String or val.is_a? Integer)
37       fail Puppet::ParseError, "Order cannot contain '/', ':', or '\n'." if val.to_s =~ /[:\n\/]/
38     end
39   end
40
41   newparam(:tag) do
42     desc "Tag name to be used by concat to collect all concat_fragments by tag name"
43   end
44
45   autorequire(:file) do
46     if catalog.resources.select {|x| x.class == Puppet::Type.type(:concat_file) and (x[:path] == self[:target] || x.title == self[:target]) }.empty?
47       warning "Target Concat_file with path of #{self[:target]} not found in the catalog"
48     end
49   end
50
51   validate do
52     # Check if target is set
53     fail Puppet::ParseError, "Target not set" if self[:target].nil?
54
55     # Check if tag is set
56     fail Puppet::ParseError, "Tag not set" if self[:tag].nil?
57
58     # Check if either source or content is set. raise error if none is set
59     fail Puppet::ParseError, "Set either 'source' or 'content'" if self[:source].nil? && self[:content].nil?
60
61     # Check if both are set, if so rais error
62     fail Puppet::ParseError, "Can't use 'source' and 'content' at the same time" if !self[:source].nil? && !self[:content].nil?
63   end
64 end