puppetmodule-stdlib 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +253 -0
- data/CONTRIBUTING.md +65 -0
- data/Gemfile +33 -0
- data/LICENSE +19 -0
- data/Modulefile +11 -0
- data/README.markdown +1173 -0
- data/README_DEVELOPER.markdown +35 -0
- data/RELEASE_PROCESS.markdown +24 -0
- data/Rakefile +2 -0
- data/lib/facter/pe_version.rb +53 -0
- data/lib/facter/puppet_vardir.rb +26 -0
- data/lib/facter/root_home.rb +19 -0
- data/lib/facter/util/puppet_settings.rb +21 -0
- data/lib/puppet/parser/functions/abs.rb +36 -0
- data/lib/puppet/parser/functions/any2array.rb +33 -0
- data/lib/puppet/parser/functions/bool2num.rb +49 -0
- data/lib/puppet/parser/functions/capitalize.rb +34 -0
- data/lib/puppet/parser/functions/chomp.rb +35 -0
- data/lib/puppet/parser/functions/chop.rb +37 -0
- data/lib/puppet/parser/functions/concat.rb +37 -0
- data/lib/puppet/parser/functions/count.rb +22 -0
- data/lib/puppet/parser/functions/defined_with_params.rb +35 -0
- data/lib/puppet/parser/functions/delete.rb +46 -0
- data/lib/puppet/parser/functions/delete_at.rb +49 -0
- data/lib/puppet/parser/functions/downcase.rb +33 -0
- data/lib/puppet/parser/functions/empty.rb +28 -0
- data/lib/puppet/parser/functions/ensure_packages.rb +24 -0
- data/lib/puppet/parser/functions/ensure_resource.rb +35 -0
- data/lib/puppet/parser/functions/flatten.rb +33 -0
- data/lib/puppet/parser/functions/floor.rb +20 -0
- data/lib/puppet/parser/functions/fqdn_rotate.rb +46 -0
- data/lib/puppet/parser/functions/get_module_path.rb +17 -0
- data/lib/puppet/parser/functions/getparam.rb +35 -0
- data/lib/puppet/parser/functions/getvar.rb +26 -0
- data/lib/puppet/parser/functions/grep.rb +33 -0
- data/lib/puppet/parser/functions/has_interface_with.rb +52 -0
- data/lib/puppet/parser/functions/has_ip_address.rb +25 -0
- data/lib/puppet/parser/functions/has_ip_network.rb +25 -0
- data/lib/puppet/parser/functions/has_key.rb +28 -0
- data/lib/puppet/parser/functions/hash.rb +41 -0
- data/lib/puppet/parser/functions/is_array.rb +22 -0
- data/lib/puppet/parser/functions/is_domain_name.rb +47 -0
- data/lib/puppet/parser/functions/is_float.rb +27 -0
- data/lib/puppet/parser/functions/is_function_available.rb +23 -0
- data/lib/puppet/parser/functions/is_hash.rb +22 -0
- data/lib/puppet/parser/functions/is_integer.rb +27 -0
- data/lib/puppet/parser/functions/is_ip_address.rb +32 -0
- data/lib/puppet/parser/functions/is_mac_address.rb +27 -0
- data/lib/puppet/parser/functions/is_numeric.rb +27 -0
- data/lib/puppet/parser/functions/is_string.rb +26 -0
- data/lib/puppet/parser/functions/join.rb +41 -0
- data/lib/puppet/parser/functions/join_keys_to_values.rb +47 -0
- data/lib/puppet/parser/functions/keys.rb +26 -0
- data/lib/puppet/parser/functions/loadyaml.rb +20 -0
- data/lib/puppet/parser/functions/lstrip.rb +33 -0
- data/lib/puppet/parser/functions/max.rb +21 -0
- data/lib/puppet/parser/functions/member.rb +44 -0
- data/lib/puppet/parser/functions/merge.rb +33 -0
- data/lib/puppet/parser/functions/min.rb +21 -0
- data/lib/puppet/parser/functions/num2bool.rb +43 -0
- data/lib/puppet/parser/functions/parsejson.rb +24 -0
- data/lib/puppet/parser/functions/parseyaml.rb +24 -0
- data/lib/puppet/parser/functions/pick.rb +29 -0
- data/lib/puppet/parser/functions/prefix.rb +45 -0
- data/lib/puppet/parser/functions/range.rb +80 -0
- data/lib/puppet/parser/functions/reject.rb +31 -0
- data/lib/puppet/parser/functions/reverse.rb +28 -0
- data/lib/puppet/parser/functions/rstrip.rb +32 -0
- data/lib/puppet/parser/functions/shuffle.rb +46 -0
- data/lib/puppet/parser/functions/size.rb +48 -0
- data/lib/puppet/parser/functions/sort.rb +27 -0
- data/lib/puppet/parser/functions/squeeze.rb +36 -0
- data/lib/puppet/parser/functions/str2bool.rb +46 -0
- data/lib/puppet/parser/functions/str2saltedsha512.rb +32 -0
- data/lib/puppet/parser/functions/strftime.rb +107 -0
- data/lib/puppet/parser/functions/strip.rb +39 -0
- data/lib/puppet/parser/functions/suffix.rb +45 -0
- data/lib/puppet/parser/functions/swapcase.rb +39 -0
- data/lib/puppet/parser/functions/time.rb +49 -0
- data/lib/puppet/parser/functions/to_bytes.rb +28 -0
- data/lib/puppet/parser/functions/type.rb +50 -0
- data/lib/puppet/parser/functions/unique.rb +51 -0
- data/lib/puppet/parser/functions/upcase.rb +41 -0
- data/lib/puppet/parser/functions/uriescape.rb +36 -0
- data/lib/puppet/parser/functions/validate_absolute_path.rb +56 -0
- data/lib/puppet/parser/functions/validate_array.rb +33 -0
- data/lib/puppet/parser/functions/validate_augeas.rb +81 -0
- data/lib/puppet/parser/functions/validate_bool.rb +34 -0
- data/lib/puppet/parser/functions/validate_cmd.rb +47 -0
- data/lib/puppet/parser/functions/validate_hash.rb +33 -0
- data/lib/puppet/parser/functions/validate_re.rb +40 -0
- data/lib/puppet/parser/functions/validate_slength.rb +52 -0
- data/lib/puppet/parser/functions/validate_string.rb +33 -0
- data/lib/puppet/parser/functions/values.rb +39 -0
- data/lib/puppet/parser/functions/values_at.rb +98 -0
- data/lib/puppet/parser/functions/zip.rb +65 -0
- data/lib/puppet/provider/file_line/ruby.rb +59 -0
- data/lib/puppet/type/anchor.rb +41 -0
- data/lib/puppet/type/file_line.rb +70 -0
- data/manifests/init.pp +20 -0
- data/manifests/stages.pp +43 -0
- data/spec/functions/defined_with_params_spec.rb +37 -0
- data/spec/functions/ensure_packages_spec.rb +42 -0
- data/spec/functions/ensure_resource_spec.rb +40 -0
- data/spec/functions/getparam_spec.rb +34 -0
- data/spec/monkey_patches/alias_should_to_must.rb +8 -0
- data/spec/monkey_patches/publicize_methods.rb +10 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/unit/facter/pe_version_spec.rb +76 -0
- data/spec/unit/facter/root_home_spec.rb +40 -0
- data/spec/unit/facter/util/puppet_settings_spec.rb +35 -0
- data/spec/unit/puppet/parser/functions/abs_spec.rb +25 -0
- data/spec/unit/puppet/parser/functions/any2array_spec.rb +55 -0
- data/spec/unit/puppet/parser/functions/bool2num_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/capitalize_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/chomp_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/chop_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/concat_spec.rb +15 -0
- data/spec/unit/puppet/parser/functions/count_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/delete_at_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/delete_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/downcase_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/empty_spec.rb +23 -0
- data/spec/unit/puppet/parser/functions/flatten_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/floor_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb +33 -0
- data/spec/unit/puppet/parser/functions/get_module_path_spec.rb +46 -0
- data/spec/unit/puppet/parser/functions/getvar_spec.rb +37 -0
- data/spec/unit/puppet/parser/functions/grep_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/has_interface_with_spec.rb +64 -0
- data/spec/unit/puppet/parser/functions/has_ip_address_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/has_ip_network_spec.rb +36 -0
- data/spec/unit/puppet/parser/functions/has_key_spec.rb +42 -0
- data/spec/unit/puppet/parser/functions/hash_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/is_array_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_domain_name_spec.rb +64 -0
- data/spec/unit/puppet/parser/functions/is_float_spec.rb +33 -0
- data/spec/unit/puppet/parser/functions/is_function_available.rb +31 -0
- data/spec/unit/puppet/parser/functions/is_hash_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_integer_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/is_ip_address_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/is_mac_address_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/is_numeric_spec.rb +39 -0
- data/spec/unit/puppet/parser/functions/is_string_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb +40 -0
- data/spec/unit/puppet/parser/functions/join_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/keys_spec.rb +21 -0
- data/spec/unit/puppet/parser/functions/lstrip_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/max_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/member_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/merge_spec.rb +47 -0
- data/spec/unit/puppet/parser/functions/min_spec.rb +27 -0
- data/spec/unit/puppet/parser/functions/num2bool_spec.rb +67 -0
- data/spec/unit/puppet/parser/functions/parsejson_spec.rb +22 -0
- data/spec/unit/puppet/parser/functions/parseyaml_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/pick_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/prefix_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/range_spec.rb +34 -0
- data/spec/unit/puppet/parser/functions/reject_spec.rb +20 -0
- data/spec/unit/puppet/parser/functions/reverse_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/rstrip_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/shuffle_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/size_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/sort_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/squeeze_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/str2bool_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb +45 -0
- data/spec/unit/puppet/parser/functions/strftime_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/strip_spec.rb +18 -0
- data/spec/unit/puppet/parser/functions/suffix_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/swapcase_spec.rb +19 -0
- data/spec/unit/puppet/parser/functions/time_spec.rb +29 -0
- data/spec/unit/puppet/parser/functions/to_bytes_spec.rb +58 -0
- data/spec/unit/puppet/parser/functions/type_spec.rb +43 -0
- data/spec/unit/puppet/parser/functions/unique_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/upcase_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/uriescape_spec.rb +24 -0
- data/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb +83 -0
- data/spec/unit/puppet/parser/functions/validate_array_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/validate_augeas_spec.rb +102 -0
- data/spec/unit/puppet/parser/functions/validate_bool_spec.rb +51 -0
- data/spec/unit/puppet/parser/functions/validate_cmd_spec.rb +81 -0
- data/spec/unit/puppet/parser/functions/validate_hash_spec.rb +43 -0
- data/spec/unit/puppet/parser/functions/validate_re_spec.rb +76 -0
- data/spec/unit/puppet/parser/functions/validate_slength_spec.rb +48 -0
- data/spec/unit/puppet/parser/functions/validate_string_spec.rb +60 -0
- data/spec/unit/puppet/parser/functions/values_at_spec.rb +38 -0
- data/spec/unit/puppet/parser/functions/values_spec.rb +31 -0
- data/spec/unit/puppet/parser/functions/zip_spec.rb +15 -0
- data/spec/unit/puppet/provider/file_line/ruby_spec.rb +127 -0
- data/spec/unit/puppet/type/anchor_spec.rb +11 -0
- data/spec/unit/puppet/type/file_line_spec.rb +69 -0
- data/spec/watchr.rb +86 -0
- data/tests/file_line.pp +9 -0
- data/tests/has_interface_with.pp +10 -0
- data/tests/has_ip_address.pp +3 -0
- data/tests/has_ip_network.pp +4 -0
- data/tests/init.pp +1 -0
- metadata +252 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Puppet::Parser::Functions
|
|
2
|
+
|
|
3
|
+
newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args|
|
|
4
|
+
Validate that all passed values are string data structures. Abort catalog
|
|
5
|
+
compilation if any value fails this check.
|
|
6
|
+
|
|
7
|
+
The following values will pass:
|
|
8
|
+
|
|
9
|
+
$my_string = "one two"
|
|
10
|
+
validate_string($my_string, 'three')
|
|
11
|
+
|
|
12
|
+
The following values will fail, causing compilation to abort:
|
|
13
|
+
|
|
14
|
+
validate_string(true)
|
|
15
|
+
validate_string([ 'some', 'array' ])
|
|
16
|
+
$undefined = undef
|
|
17
|
+
validate_string($undefined)
|
|
18
|
+
|
|
19
|
+
ENDHEREDOC
|
|
20
|
+
|
|
21
|
+
unless args.length > 0 then
|
|
22
|
+
raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
args.each do |arg|
|
|
26
|
+
unless arg.is_a?(String)
|
|
27
|
+
raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#
|
|
2
|
+
# values.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:values, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
When given a hash this function will return the values of that hash.
|
|
8
|
+
|
|
9
|
+
*Examples:*
|
|
10
|
+
|
|
11
|
+
$hash = {
|
|
12
|
+
'a' => 1,
|
|
13
|
+
'b' => 2,
|
|
14
|
+
'c' => 3,
|
|
15
|
+
}
|
|
16
|
+
values($hash)
|
|
17
|
+
|
|
18
|
+
This example would return:
|
|
19
|
+
|
|
20
|
+
[1,2,3]
|
|
21
|
+
EOS
|
|
22
|
+
) do |arguments|
|
|
23
|
+
|
|
24
|
+
raise(Puppet::ParseError, "values(): Wrong number of arguments " +
|
|
25
|
+
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
26
|
+
|
|
27
|
+
hash = arguments[0]
|
|
28
|
+
|
|
29
|
+
unless hash.is_a?(Hash)
|
|
30
|
+
raise(Puppet::ParseError, 'values(): Requires hash to work with')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
result = hash.values
|
|
34
|
+
|
|
35
|
+
return result
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#
|
|
2
|
+
# values_at.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:values_at, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Finds value inside an array based on location.
|
|
8
|
+
|
|
9
|
+
The first argument is the array you want to analyze, and the second element can
|
|
10
|
+
be a combination of:
|
|
11
|
+
|
|
12
|
+
* A single numeric index
|
|
13
|
+
* A range in the form of 'start-stop' (eg. 4-9)
|
|
14
|
+
* An array combining the above
|
|
15
|
+
|
|
16
|
+
*Examples*:
|
|
17
|
+
|
|
18
|
+
values_at(['a','b','c'], 2)
|
|
19
|
+
|
|
20
|
+
Would return ['c'].
|
|
21
|
+
|
|
22
|
+
values_at(['a','b','c'], ["0-1"])
|
|
23
|
+
|
|
24
|
+
Would return ['a','b'].
|
|
25
|
+
|
|
26
|
+
values_at(['a','b','c','d','e'], [0, "2-3"])
|
|
27
|
+
|
|
28
|
+
Would return ['a','c','d'].
|
|
29
|
+
EOS
|
|
30
|
+
) do |arguments|
|
|
31
|
+
|
|
32
|
+
raise(Puppet::ParseError, "values_at(): Wrong number of " +
|
|
33
|
+
"arguments given (#{arguments.size} for 2)") if arguments.size < 2
|
|
34
|
+
|
|
35
|
+
array = arguments.shift
|
|
36
|
+
|
|
37
|
+
unless array.is_a?(Array)
|
|
38
|
+
raise(Puppet::ParseError, 'values_at(): Requires array to work with')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
indices = [arguments.shift].flatten() # Get them all ... Pokemon ...
|
|
42
|
+
|
|
43
|
+
if not indices or indices.empty?
|
|
44
|
+
raise(Puppet::ParseError, 'values_at(): You must provide ' +
|
|
45
|
+
'at least one positive index to collect')
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
result = []
|
|
49
|
+
indices_list = []
|
|
50
|
+
|
|
51
|
+
indices.each do |i|
|
|
52
|
+
if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/)
|
|
53
|
+
start = m[1].to_i
|
|
54
|
+
stop = m[3].to_i
|
|
55
|
+
|
|
56
|
+
type = m[2]
|
|
57
|
+
|
|
58
|
+
if start > stop
|
|
59
|
+
raise(Puppet::ParseError, 'values_at(): Stop index in ' +
|
|
60
|
+
'given indices range is smaller than the start index')
|
|
61
|
+
elsif stop > array.size - 1 # First element is at index 0 is it not?
|
|
62
|
+
raise(Puppet::ParseError, 'values_at(): Stop index in ' +
|
|
63
|
+
'given indices range exceeds array size')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
range = case type
|
|
67
|
+
when /^(\.\.|\-)$/ then (start .. stop)
|
|
68
|
+
when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ...
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
range.each { |i| indices_list << i.to_i }
|
|
72
|
+
else
|
|
73
|
+
# Only positive numbers allowed in this case ...
|
|
74
|
+
if not i.match(/^\d+$/)
|
|
75
|
+
raise(Puppet::ParseError, 'values_at(): Unknown format ' +
|
|
76
|
+
'of given index')
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# In Puppet numbers are often string-encoded ...
|
|
80
|
+
i = i.to_i
|
|
81
|
+
|
|
82
|
+
if i > array.size - 1 # Same story. First element is at index 0 ...
|
|
83
|
+
raise(Puppet::ParseError, 'values_at(): Given index ' +
|
|
84
|
+
'exceeds array size')
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
indices_list << i
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# We remove nil values as they make no sense in Puppet DSL ...
|
|
92
|
+
result = indices_list.collect { |i| array[i] }.compact
|
|
93
|
+
|
|
94
|
+
return result
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#
|
|
2
|
+
# zip.rb
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module Puppet::Parser::Functions
|
|
6
|
+
newfunction(:zip, :type => :rvalue, :doc => <<-EOS
|
|
7
|
+
Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments.
|
|
8
|
+
|
|
9
|
+
*Example:*
|
|
10
|
+
|
|
11
|
+
zip(['1','2','3'],['4','5','6'])
|
|
12
|
+
|
|
13
|
+
Would result in:
|
|
14
|
+
|
|
15
|
+
["1", "4"], ["2", "5"], ["3", "6"]
|
|
16
|
+
EOS
|
|
17
|
+
) do |arguments|
|
|
18
|
+
|
|
19
|
+
# Technically we support three arguments but only first is mandatory ...
|
|
20
|
+
raise(Puppet::ParseError, "zip(): Wrong number of arguments " +
|
|
21
|
+
"given (#{arguments.size} for 2)") if arguments.size < 2
|
|
22
|
+
|
|
23
|
+
a = arguments[0]
|
|
24
|
+
b = arguments[1]
|
|
25
|
+
|
|
26
|
+
unless a.is_a?(Array) and b.is_a?(Array)
|
|
27
|
+
raise(Puppet::ParseError, 'zip(): Requires array to work with')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
flatten = arguments[2] if arguments[2]
|
|
31
|
+
|
|
32
|
+
if flatten
|
|
33
|
+
klass = flatten.class
|
|
34
|
+
|
|
35
|
+
# We can have either true or false, or string which resembles boolean ...
|
|
36
|
+
unless [FalseClass, TrueClass, String].include?(klass)
|
|
37
|
+
raise(Puppet::ParseError, 'zip(): Requires either ' +
|
|
38
|
+
'boolean or string to work with')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if flatten.is_a?(String)
|
|
42
|
+
# We consider all the yes, no, y, n and so on too ...
|
|
43
|
+
flatten = case flatten
|
|
44
|
+
#
|
|
45
|
+
# This is how undef looks like in Puppet ...
|
|
46
|
+
# We yield false in this case.
|
|
47
|
+
#
|
|
48
|
+
when /^$/, '' then false # Empty string will be false ...
|
|
49
|
+
when /^(1|t|y|true|yes)$/ then true
|
|
50
|
+
when /^(0|f|n|false|no)$/ then false
|
|
51
|
+
when /^(undef|undefined)$/ then false # This is not likely to happen ...
|
|
52
|
+
else
|
|
53
|
+
raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
result = a.zip(b)
|
|
59
|
+
result = flatten ? result.flatten : result
|
|
60
|
+
|
|
61
|
+
return result
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# vim: set ts=2 sw=2 et :
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
|
|
2
|
+
Puppet::Type.type(:file_line).provide(:ruby) do
|
|
3
|
+
|
|
4
|
+
def exists?
|
|
5
|
+
lines.find do |line|
|
|
6
|
+
line.chomp == resource[:line].chomp
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create
|
|
11
|
+
if resource[:match]
|
|
12
|
+
handle_create_with_match()
|
|
13
|
+
else
|
|
14
|
+
handle_create_without_match()
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def destroy
|
|
19
|
+
local_lines = lines
|
|
20
|
+
File.open(resource[:path],'w') do |fh|
|
|
21
|
+
fh.write(local_lines.reject{|l| l.chomp == resource[:line] }.join(''))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
def lines
|
|
27
|
+
# If this type is ever used with very large files, we should
|
|
28
|
+
# write this in a different way, using a temp
|
|
29
|
+
# file; for now assuming that this type is only used on
|
|
30
|
+
# small-ish config files that can fit into memory without
|
|
31
|
+
# too much trouble.
|
|
32
|
+
@lines ||= File.readlines(resource[:path])
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def handle_create_with_match()
|
|
36
|
+
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
|
|
37
|
+
match_count = lines.select { |l| regex.match(l) }.size
|
|
38
|
+
if match_count > 1
|
|
39
|
+
raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
|
|
40
|
+
end
|
|
41
|
+
File.open(resource[:path], 'w') do |fh|
|
|
42
|
+
lines.each do |l|
|
|
43
|
+
fh.puts(regex.match(l) ? resource[:line] : l)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if (match_count == 0)
|
|
47
|
+
fh.puts(resource[:line])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def handle_create_without_match
|
|
53
|
+
File.open(resource[:path], 'a') do |fh|
|
|
54
|
+
fh.puts resource[:line]
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Puppet::Type.newtype(:anchor) do
|
|
2
|
+
desc <<-'ENDOFDESC'
|
|
3
|
+
A simple resource type intended to be used as an anchor in a composite class.
|
|
4
|
+
|
|
5
|
+
In Puppet 2.6, when a class declares another class, the resources in the
|
|
6
|
+
interior class are not contained by the exterior class. This interacts badly
|
|
7
|
+
with the pattern of composing complex modules from smaller classes, as it
|
|
8
|
+
makes it impossible for end users to specify order relationships between the
|
|
9
|
+
exterior class and other modules.
|
|
10
|
+
|
|
11
|
+
The anchor type lets you work around this. By sandwiching any interior
|
|
12
|
+
classes between two no-op resources that _are_ contained by the exterior
|
|
13
|
+
class, you can ensure that all resources in the module are contained.
|
|
14
|
+
|
|
15
|
+
class ntp {
|
|
16
|
+
# These classes will have the correct order relationship with each
|
|
17
|
+
# other. However, without anchors, they won't have any order
|
|
18
|
+
# relationship to Class['ntp'].
|
|
19
|
+
class { 'ntp::package': }
|
|
20
|
+
-> class { 'ntp::config': }
|
|
21
|
+
-> class { 'ntp::service': }
|
|
22
|
+
|
|
23
|
+
# These two resources "anchor" the composed classes within the ntp
|
|
24
|
+
# class.
|
|
25
|
+
anchor { 'ntp::begin': } -> Class['ntp::package']
|
|
26
|
+
Class['ntp::service'] -> anchor { 'ntp::end': }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
This allows the end user of the ntp module to establish require and before
|
|
30
|
+
relationships with Class['ntp']:
|
|
31
|
+
|
|
32
|
+
class { 'ntp': } -> class { 'mcollective': }
|
|
33
|
+
class { 'mcollective': } -> class { 'ntp': }
|
|
34
|
+
|
|
35
|
+
ENDOFDESC
|
|
36
|
+
|
|
37
|
+
newparam :name do
|
|
38
|
+
desc "The name of the anchor resource."
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Puppet::Type.newtype(:file_line) do
|
|
2
|
+
|
|
3
|
+
desc <<-EOT
|
|
4
|
+
Ensures that a given line is contained within a file. The implementation
|
|
5
|
+
matches the full line, including whitespace at the beginning and end. If
|
|
6
|
+
the line is not contained in the given file, Puppet will add the line to
|
|
7
|
+
ensure the desired state. Multiple resources may be declared to manage
|
|
8
|
+
multiple lines in the same file.
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
|
|
12
|
+
file_line { 'sudo_rule':
|
|
13
|
+
path => '/etc/sudoers',
|
|
14
|
+
line => '%sudo ALL=(ALL) ALL',
|
|
15
|
+
}
|
|
16
|
+
file_line { 'sudo_rule_nopw':
|
|
17
|
+
path => '/etc/sudoers',
|
|
18
|
+
line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
In this example, Puppet will ensure both of the specified lines are
|
|
22
|
+
contained in the file /etc/sudoers.
|
|
23
|
+
|
|
24
|
+
EOT
|
|
25
|
+
|
|
26
|
+
ensurable do
|
|
27
|
+
defaultvalues
|
|
28
|
+
defaultto :present
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
newparam(:name, :namevar => true) do
|
|
32
|
+
desc 'An arbitrary name used as the identity of the resource.'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
newparam(:match) do
|
|
36
|
+
desc 'An optional regular expression to run against existing lines in the file;\n' +
|
|
37
|
+
'if a match is found, we replace that line rather than adding a new line.'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
newparam(:line) do
|
|
41
|
+
desc 'The line to be appended to the file located by the path parameter.'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
newparam(:path) do
|
|
45
|
+
desc 'The file Puppet will ensure contains the line specified by the line parameter.'
|
|
46
|
+
validate do |value|
|
|
47
|
+
unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/))
|
|
48
|
+
raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Autorequire the file resource if it's being managed
|
|
54
|
+
autorequire(:file) do
|
|
55
|
+
self[:path]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
validate do
|
|
59
|
+
unless self[:line] and self[:path]
|
|
60
|
+
raise(Puppet::Error, "Both line and path are required attributes")
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if (self[:match])
|
|
64
|
+
unless Regexp.new(self[:match]).match(self[:line])
|
|
65
|
+
raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
70
|
+
end
|
data/manifests/init.pp
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Class: stdlib
|
|
2
|
+
#
|
|
3
|
+
# This module manages stdlib. Most of stdlib's features are automatically
|
|
4
|
+
# loaded by Puppet, but this class should be declared in order to use the
|
|
5
|
+
# standardized run stages.
|
|
6
|
+
#
|
|
7
|
+
# Parameters: none
|
|
8
|
+
#
|
|
9
|
+
# Actions:
|
|
10
|
+
#
|
|
11
|
+
# Declares all other classes in the stdlib module. Currently, this consists
|
|
12
|
+
# of stdlib::stages.
|
|
13
|
+
#
|
|
14
|
+
# Requires: nothing
|
|
15
|
+
#
|
|
16
|
+
class stdlib {
|
|
17
|
+
|
|
18
|
+
class { 'stdlib::stages': }
|
|
19
|
+
|
|
20
|
+
}
|
data/manifests/stages.pp
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Class: stdlib::stages
|
|
2
|
+
#
|
|
3
|
+
# This class manages a standard set of run stages for Puppet. It is managed by
|
|
4
|
+
# the stdlib class, and should not be declared independently.
|
|
5
|
+
#
|
|
6
|
+
# The high level stages are (in order):
|
|
7
|
+
#
|
|
8
|
+
# * setup
|
|
9
|
+
# * main
|
|
10
|
+
# * runtime
|
|
11
|
+
# * setup_infra
|
|
12
|
+
# * deploy_infra
|
|
13
|
+
# * setup_app
|
|
14
|
+
# * deploy_app
|
|
15
|
+
# * deploy
|
|
16
|
+
#
|
|
17
|
+
# Parameters: none
|
|
18
|
+
#
|
|
19
|
+
# Actions:
|
|
20
|
+
#
|
|
21
|
+
# Declares various run-stages for deploying infrastructure,
|
|
22
|
+
# language runtimes, and application layers.
|
|
23
|
+
#
|
|
24
|
+
# Requires: nothing
|
|
25
|
+
#
|
|
26
|
+
# Sample Usage:
|
|
27
|
+
#
|
|
28
|
+
# node default {
|
|
29
|
+
# include stdlib
|
|
30
|
+
# class { java: stage => 'runtime' }
|
|
31
|
+
# }
|
|
32
|
+
#
|
|
33
|
+
class stdlib::stages {
|
|
34
|
+
|
|
35
|
+
stage { 'setup': before => Stage['main'] }
|
|
36
|
+
stage { 'runtime': require => Stage['main'] }
|
|
37
|
+
-> stage { 'setup_infra': }
|
|
38
|
+
-> stage { 'deploy_infra': }
|
|
39
|
+
-> stage { 'setup_app': }
|
|
40
|
+
-> stage { 'deploy_app': }
|
|
41
|
+
-> stage { 'deploy': }
|
|
42
|
+
|
|
43
|
+
}
|