puppet 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +123 -0
- data/conf/redhat/puppet.spec +8 -2
- data/conf/solaris/smf/svc-puppetd +1 -1
- data/conf/solaris/smf/svc-puppetmasterd +1 -1
- data/conf/suse/client.init +4 -4
- data/conf/suse/fileserver.conf +12 -0
- data/conf/suse/logrotate +10 -0
- data/conf/suse/puppet.conf +25 -0
- data/conf/suse/puppet.spec +114 -49
- data/conf/suse/ruby-env.patch +17 -0
- data/conf/suse/server.init +4 -4
- data/ext/logcheck/puppet +23 -23
- data/ext/puppet-load.rb +357 -0
- data/ext/puppetstoredconfigclean.rb +3 -3
- data/ext/rack/files/config.ru +3 -5
- data/ext/vim/syntax/puppet.vim +6 -5
- data/install.rb +12 -11
- data/lib/puppet.rb +1 -1
- data/lib/puppet/agent.rb +3 -1
- data/lib/puppet/application.rb +2 -3
- data/lib/puppet/application/agent.rb +4 -0
- data/lib/puppet/application/apply.rb +14 -6
- data/lib/puppet/application/describe.rb +1 -1
- data/lib/puppet/application/doc.rb +2 -36
- data/lib/puppet/application/master.rb +0 -3
- data/lib/puppet/application/queue.rb +1 -0
- data/lib/puppet/configurer.rb +4 -0
- data/lib/puppet/daemon.rb +1 -1
- data/lib/puppet/defaults.rb +38 -44
- data/lib/puppet/file_serving/indirection_hooks.rb +2 -2
- data/lib/puppet/indirector/facts/memory.rb +1 -1
- data/lib/puppet/indirector/node/exec.rb +1 -1
- data/lib/puppet/indirector/node/ldap.rb +9 -53
- data/lib/puppet/indirector/node/memory.rb +1 -1
- data/lib/puppet/indirector/yaml.rb +6 -9
- data/lib/puppet/network/format_handler.rb +6 -0
- data/lib/puppet/network/formats.rb +4 -4
- data/lib/puppet/network/http/handler.rb +1 -1
- data/lib/puppet/network/http/rack.rb +3 -0
- data/lib/puppet/network/http/rack/rest.rb +1 -1
- data/lib/puppet/network/rest_authconfig.rb +6 -3
- data/lib/puppet/node/environment.rb +15 -5
- data/lib/puppet/parameter/value_collection.rb +3 -3
- data/lib/puppet/parser/ast/function.rb +0 -1
- data/lib/puppet/parser/ast/leaf.rb +1 -1
- data/lib/puppet/parser/ast/resource.rb +4 -3
- data/lib/puppet/parser/ast/resource_reference.rb +9 -2
- data/lib/puppet/parser/compiler.rb +12 -14
- data/lib/puppet/parser/files.rb +1 -1
- data/lib/puppet/parser/functions.rb +2 -2
- data/lib/puppet/parser/functions/defined.rb +1 -1
- data/lib/puppet/parser/functions/extlookup.rb +157 -0
- data/lib/puppet/parser/functions/file.rb +1 -1
- data/lib/puppet/parser/functions/inline_template.rb +6 -5
- data/lib/puppet/parser/functions/md5.rb +5 -0
- data/lib/puppet/parser/functions/realize.rb +1 -1
- data/lib/puppet/parser/functions/regsubst.rb +19 -19
- data/lib/puppet/parser/functions/require.rb +2 -3
- data/lib/puppet/parser/functions/split.rb +1 -1
- data/lib/puppet/parser/functions/sprintf.rb +1 -1
- data/lib/puppet/parser/functions/template.rb +4 -2
- data/lib/puppet/parser/functions/versioncmp.rb +12 -12
- data/lib/puppet/parser/lexer.rb +13 -14
- data/lib/puppet/parser/resource.rb +2 -7
- data/lib/puppet/parser/resource/param.rb +1 -1
- data/lib/puppet/parser/scope.rb +35 -0
- data/lib/puppet/parser/type_loader.rb +1 -1
- data/lib/puppet/property.rb +5 -5
- data/lib/puppet/provider.rb +3 -3
- data/lib/puppet/provider/group/groupadd.rb +1 -1
- data/lib/puppet/provider/group/ldap.rb +3 -3
- data/lib/puppet/provider/group/pw.rb +1 -1
- data/lib/puppet/provider/package/apple.rb +1 -1
- data/lib/puppet/provider/package/apt.rb +5 -1
- data/lib/puppet/provider/package/aptitude.rb +1 -1
- data/lib/puppet/provider/package/aptrpm.rb +1 -1
- data/lib/puppet/provider/package/blastwave.rb +1 -1
- data/lib/puppet/provider/package/dpkg.rb +2 -2
- data/lib/puppet/provider/package/fink.rb +1 -1
- data/lib/puppet/provider/package/gem.rb +1 -1
- data/lib/puppet/provider/package/openbsd.rb +1 -1
- data/lib/puppet/provider/package/rpm.rb +1 -1
- data/lib/puppet/provider/package/rug.rb +1 -1
- data/lib/puppet/provider/package/sunfreeware.rb +2 -2
- data/lib/puppet/provider/package/up2date.rb +1 -1
- data/lib/puppet/provider/package/urpmi.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/package/zypper.rb +1 -1
- data/lib/puppet/provider/service/base.rb +1 -1
- data/lib/puppet/provider/service/bsd.rb +2 -2
- data/lib/puppet/provider/service/debian.rb +2 -2
- data/lib/puppet/provider/service/gentoo.rb +2 -2
- data/lib/puppet/provider/service/init.rb +2 -2
- data/lib/puppet/provider/service/redhat.rb +2 -2
- data/lib/puppet/provider/user/ldap.rb +3 -3
- data/lib/puppet/provider/user/pw.rb +1 -1
- data/lib/puppet/provider/user/user_role_add.rb +1 -1
- data/lib/puppet/provider/user/useradd.rb +1 -1
- data/lib/puppet/rails/host.rb +1 -0
- data/lib/puppet/reference/configuration.rb +37 -34
- data/lib/puppet/reference/indirection.rb +3 -4
- data/lib/puppet/reference/metaparameter.rb +0 -8
- data/lib/puppet/reference/network.rb +6 -4
- data/lib/puppet/reference/providers.rb +4 -4
- data/lib/puppet/reference/report.rb +5 -6
- data/lib/puppet/reference/type.rb +14 -14
- data/lib/puppet/reports/http.rb +1 -1
- data/lib/puppet/reports/rrdgraph.rb +8 -9
- data/lib/puppet/reports/store.rb +2 -2
- data/lib/puppet/reports/tagmail.rb +12 -13
- data/lib/puppet/resource.rb +15 -115
- data/lib/puppet/resource/catalog.rb +1 -1
- data/lib/puppet/resource/type.rb +26 -3
- data/lib/puppet/resource/type_collection.rb +3 -6
- data/lib/puppet/simple_graph.rb +4 -5
- data/lib/puppet/transaction/resource_harness.rb +1 -1
- data/lib/puppet/type.rb +100 -92
- data/lib/puppet/type/augeas.rb +44 -45
- data/lib/puppet/type/computer.rb +2 -2
- data/lib/puppet/type/cron.rb +29 -29
- data/lib/puppet/type/exec.rb +66 -67
- data/lib/puppet/type/file.rb +25 -25
- data/lib/puppet/type/file/content.rb +7 -1
- data/lib/puppet/type/file/ensure.rb +13 -13
- data/lib/puppet/type/file/mode.rb +6 -6
- data/lib/puppet/type/file/selcontext.rb +5 -5
- data/lib/puppet/type/file/source.rb +36 -26
- data/lib/puppet/type/filebucket.rb +5 -6
- data/lib/puppet/type/group.rb +1 -2
- data/lib/puppet/type/host.rb +3 -6
- data/lib/puppet/type/k5login.rb +3 -3
- data/lib/puppet/type/macauthorization.rb +1 -2
- data/lib/puppet/type/mailalias.rb +0 -1
- data/lib/puppet/type/maillist.rb +0 -1
- data/lib/puppet/type/mcx.rb +9 -9
- data/lib/puppet/type/mount.rb +9 -10
- data/lib/puppet/type/notify.rb +0 -1
- data/lib/puppet/type/package.rb +34 -36
- data/lib/puppet/type/resources.rb +1 -5
- data/lib/puppet/type/schedule.rb +9 -12
- data/lib/puppet/type/selboolean.rb +2 -7
- data/lib/puppet/type/selmodule.rb +3 -4
- data/lib/puppet/type/service.rb +9 -9
- data/lib/puppet/type/ssh_authorized_key.rb +2 -3
- data/lib/puppet/type/sshkey.rb +4 -7
- data/lib/puppet/type/stage.rb +5 -4
- data/lib/puppet/type/tidy.rb +3 -3
- data/lib/puppet/type/user.rb +1 -2
- data/lib/puppet/type/whit.rb +7 -0
- data/lib/puppet/type/yumrepo.rb +16 -3
- data/lib/puppet/type/zfs.rb +1 -2
- data/lib/puppet/type/zone.rb +28 -28
- data/lib/puppet/type/zpool.rb +10 -5
- data/lib/puppet/util/autoload.rb +17 -5
- data/lib/puppet/util/cacher.rb +15 -10
- data/lib/puppet/util/command_line/puppetdoc +5 -5
- data/lib/puppet/util/command_line/puppetrun +0 -2
- data/lib/puppet/util/command_line/ralsh +13 -13
- data/lib/puppet/util/docs.rb +5 -12
- data/lib/puppet/util/monkey_patches.rb +5 -2
- data/lib/puppet/util/nagios_maker.rb +4 -5
- data/lib/puppet/util/provider_features.rb +2 -2
- data/lib/puppet/util/rdoc.rb +1 -1
- data/lib/puppet/util/rdoc/parser.rb +5 -3
- data/lib/puppet/util/reference.rb +3 -52
- data/man/man5/puppet.conf.5 +2072 -1526
- data/man/man8/filebucket.8 +104 -106
- data/man/man8/pi.8 +14 -47
- data/man/man8/puppet.8 +8 -9
- data/man/man8/puppetca.8 +168 -129
- data/man/man8/puppetd.8 +282 -226
- data/man/man8/puppetdoc.8 +103 -103
- data/man/man8/puppetmasterd.8 +51 -71
- data/man/man8/puppetqd.8 +18 -53
- data/man/man8/puppetrun.8 +163 -143
- data/man/man8/ralsh.8 +77 -114
- data/spec/integration/indirector/bucket_file/rest_spec.rb +1 -0
- data/spec/integration/indirector/certificate/rest_spec.rb +1 -0
- data/spec/integration/indirector/certificate_request/rest_spec.rb +1 -0
- data/spec/integration/indirector/certificate_revocation_list/rest_spec.rb +1 -0
- data/spec/integration/indirector/report/rest_spec.rb +1 -0
- data/spec/integration/indirector/rest_spec.rb +1 -0
- data/spec/integration/network/server/webrick_spec.rb +1 -0
- data/spec/integration/parser/compiler_spec.rb +43 -0
- data/spec/integration/provider/mailalias/aliases_spec.rb +5 -5
- data/spec/integration/ssl/certificate_authority_spec.rb +1 -0
- data/spec/integration/ssl/certificate_request_spec.rb +1 -0
- data/spec/integration/ssl/certificate_revocation_list_spec.rb +1 -0
- data/spec/integration/ssl/host_spec.rb +1 -0
- data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -1
- data/spec/monkey_patches/publicize_methods.rb +11 -0
- data/spec/shared_behaviours/file_serving.rb +12 -1
- data/spec/spec_helper.rb +6 -25
- data/spec/unit/application/apply_spec.rb +22 -4
- data/spec/unit/application/cert_spec.rb +1 -1
- data/spec/unit/application/doc_spec.rb +0 -19
- data/spec/unit/application/master_spec.rb +1 -1
- data/spec/unit/application_spec.rb +2 -12
- data/spec/unit/indirector/node/ldap_spec.rb +19 -21
- data/spec/unit/indirector/yaml_spec.rb +18 -6
- data/spec/unit/network/http/rack/rest_spec.rb +3 -3
- data/spec/unit/network/http/webrick/rest_spec.rb +1 -0
- data/spec/unit/node/environment_spec.rb +32 -3
- data/spec/unit/node/facts_spec.rb +13 -2
- data/spec/unit/parameter/value_collection_spec.rb +2 -2
- data/spec/unit/parser/ast/leaf_spec.rb +4 -0
- data/spec/unit/parser/ast/resource_reference_spec.rb +0 -5
- data/spec/unit/parser/ast/resource_spec.rb +7 -0
- data/spec/unit/parser/compiler_spec.rb +12 -1
- data/spec/unit/parser/files_spec.rb +3 -3
- data/spec/unit/parser/functions/extlookup_spec.rb +95 -0
- data/spec/unit/parser/functions/include_spec.rb +33 -0
- data/spec/unit/parser/functions/require_spec.rb +1 -1
- data/spec/unit/parser/functions/tag_spec.rb +1 -0
- data/spec/unit/parser/lexer_spec.rb +10 -1
- data/spec/unit/parser/resource_spec.rb +3 -9
- data/spec/unit/parser/type_loader_spec.rb +1 -1
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +4 -2
- data/spec/unit/rails/resource_spec.rb +1 -1
- data/spec/unit/reports/tagmail_spec.rb +2 -2
- data/spec/unit/resource/catalog_spec.rb +1 -1
- data/spec/unit/resource/type_collection_spec.rb +35 -0
- data/spec/unit/resource/type_spec.rb +19 -1
- data/spec/unit/resource_spec.rb +0 -36
- data/spec/unit/simple_graph_spec.rb +12 -2
- data/spec/unit/transaction/resource_harness_spec.rb +1 -1
- data/spec/unit/type/file/content_spec.rb +2 -1
- data/spec/unit/type/schedule_spec.rb +1 -1
- data/spec/unit/type/service_spec.rb +8 -0
- data/spec/unit/type/user_spec.rb +5 -0
- data/spec/unit/util/backups_spec.rb +0 -1
- data/spec/unit/util/rdoc/parser_spec.rb +3 -3
- data/spec/unit/util/rdoc_spec.rb +13 -0
- data/test/certmgr/support.rb +2 -1
- data/test/language/parser.rb +6 -6
- data/test/lib/puppettest.rb +3 -23
- data/test/lib/puppettest/fakes.rb +1 -1
- data/test/lib/puppettest/support/assertions.rb +0 -2
- data/test/lib/puppettest/support/utils.rb +25 -20
- data/test/ral/manager/attributes.rb +4 -1
- metadata +15 -9
- data/conf/suse/puppet.suse.patch +0 -16
- data/ext/extlookup.rb +0 -181
- data/ext/puppetlast +0 -16
- data/tasks/rake/tracdocs.rake +0 -8
- data/test/lib/mocha_standalone.rb +0 -2
@@ -3,7 +3,7 @@ Puppet::Parser::Functions::newfunction(:defined, :type => :rvalue, :doc => "Dete
|
|
3
3
|
type is defined, either as a native type or a defined type, or whether a class is defined.
|
4
4
|
This is useful for checking whether a class is defined and only including it if it is.
|
5
5
|
This function can also test whether a resource has been defined, using resource references
|
6
|
-
(e.g.,
|
6
|
+
(e.g., `if defined(File['/tmp/myfile']) { ... }`). This function is unfortunately
|
7
7
|
dependent on the parse order of the configuration when testing whether a resource is defined.") do |vals|
|
8
8
|
result = false
|
9
9
|
vals = [vals] unless vals.is_a?(Array)
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
module Puppet::Parser::Functions
|
4
|
+
newfunction(:extlookup,
|
5
|
+
:type => :rvalue,
|
6
|
+
:doc => "This is a parser function to read data from external files, this version
|
7
|
+
uses CSV files but the concept can easily be adjust for databases, yaml
|
8
|
+
or any other queryable data source.
|
9
|
+
|
10
|
+
The object of this is to make it obvious when it's being used, rather than
|
11
|
+
magically loading data in when an module is loaded I prefer to look at the code
|
12
|
+
and see statements like:
|
13
|
+
|
14
|
+
$snmp_contact = extlookup(\"snmp_contact\")
|
15
|
+
|
16
|
+
The above snippet will load the snmp_contact value from CSV files, this in its
|
17
|
+
own is useful but a common construct in puppet manifests is something like this:
|
18
|
+
|
19
|
+
case $domain {
|
20
|
+
\"myclient.com\": { $snmp_contact = \"John Doe <john@myclient.com>\" }
|
21
|
+
default: { $snmp_contact = \"My Support <support@my.com>\" }
|
22
|
+
}
|
23
|
+
|
24
|
+
Over time there will be a lot of this kind of thing spread all over your manifests
|
25
|
+
and adding an additional client involves grepping through manifests to find all the
|
26
|
+
places where you have constructs like this.
|
27
|
+
|
28
|
+
This is a data problem and shouldn't be handled in code, a using this function you
|
29
|
+
can do just that.
|
30
|
+
|
31
|
+
First you configure it in site.pp:
|
32
|
+
|
33
|
+
$extlookup_datadir = \"/etc/puppet/manifests/extdata\"
|
34
|
+
$extlookup_precedence = [\"%{fqdn}\", \"domain_%{domain}\", \"common\"]
|
35
|
+
|
36
|
+
The array tells the code how to resolve values, first it will try to find it in
|
37
|
+
web1.myclient.com.csv then in domain_myclient.com.csv and finally in common.csv
|
38
|
+
|
39
|
+
Now create the following data files in /etc/puppet/manifests/extdata:
|
40
|
+
|
41
|
+
domain_myclient.com.csv:
|
42
|
+
snmp_contact,John Doe <john@myclient.com>
|
43
|
+
root_contact,support@%{domain}
|
44
|
+
client_trusted_ips,192.168.1.130,192.168.10.0/24
|
45
|
+
|
46
|
+
common.csv:
|
47
|
+
snmp_contact,My Support <support@my.com>
|
48
|
+
root_contact,support@my.com
|
49
|
+
|
50
|
+
Now you can replace the case statement with the simple single line to achieve
|
51
|
+
the exact same outcome:
|
52
|
+
|
53
|
+
$snmp_contact = extlookup(\"snmp_contact\")
|
54
|
+
|
55
|
+
The obove code shows some other features, you can use any fact or variable that
|
56
|
+
is in scope by simply using %{varname} in your data files, you can return arrays
|
57
|
+
by just having multiple values in the csv after the initial variable name.
|
58
|
+
|
59
|
+
In the event that a variable is nowhere to be found a critical error will be raised
|
60
|
+
that will prevent your manifest from compiling, this is to avoid accidentally putting
|
61
|
+
in empty values etc. You can however specify a default value:
|
62
|
+
|
63
|
+
$ntp_servers = extlookup(\"ntp_servers\", \"1.${country}.pool.ntp.org\")
|
64
|
+
|
65
|
+
In this case it will default to \"1.${country}.pool.ntp.org\" if nothing is defined in
|
66
|
+
any data file.
|
67
|
+
|
68
|
+
You can also specify an additional data file to search first before any others at use
|
69
|
+
time, for example:
|
70
|
+
|
71
|
+
$version = extlookup(\"rsyslog_version\", \"present\", \"packages\")
|
72
|
+
package{\"rsyslog\": ensure => $version }
|
73
|
+
|
74
|
+
This will look for a version configured in packages.csv and then in the rest as configured
|
75
|
+
by $extlookup_precedence if it's not found anywhere it will default to `present`, this kind
|
76
|
+
of use case makes puppet a lot nicer for managing large amounts of packages since you do not
|
77
|
+
need to edit a load of manifests to do simple things like adjust a desired version number.
|
78
|
+
|
79
|
+
Precedence values can have variables embedded in them in the form %{fqdn}, you could for example do:
|
80
|
+
|
81
|
+
$extlookup_precedence = [\"hosts/%{fqdn}\", \"common\"]
|
82
|
+
|
83
|
+
This will result in /path/to/extdata/hosts/your.box.com.csv being searched.
|
84
|
+
|
85
|
+
This is for back compatibility to interpolate variables with %. % interpolation is a workaround for a problem that has been fixed: Puppet variable interpolation at top scope used to only happen on each run.") do |args|
|
86
|
+
|
87
|
+
key = args[0]
|
88
|
+
|
89
|
+
default = args[1]
|
90
|
+
datafile = args[2]
|
91
|
+
|
92
|
+
raise Puppet::ParseError, ("extlookup(): wrong number of arguments (#{args.length}; must be <= 3)") if args.length > 3
|
93
|
+
|
94
|
+
extlookup_datadir = lookupvar('extlookup_datadir')
|
95
|
+
extlookup_precedence = Array.new
|
96
|
+
|
97
|
+
extlookup_precedence = lookupvar('extlookup_precedence').collect do |var|
|
98
|
+
var.gsub(/%\{(.+?)\}/) do |capture|
|
99
|
+
lookupvar($1)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
datafiles = Array.new
|
104
|
+
|
105
|
+
# if we got a custom data file, put it first in the array of search files
|
106
|
+
if datafile != ""
|
107
|
+
datafiles << extlookup_datadir + "/#{datafile}.csv" if File.exists?(extlookup_datadir + "/#{datafile}.csv")
|
108
|
+
end
|
109
|
+
|
110
|
+
extlookup_precedence.each do |d|
|
111
|
+
datafiles << extlookup_datadir + "/#{d}.csv"
|
112
|
+
end
|
113
|
+
|
114
|
+
desired = nil
|
115
|
+
|
116
|
+
datafiles.each do |file|
|
117
|
+
if desired.nil?
|
118
|
+
if File.exists?(file)
|
119
|
+
result = CSV.read(file).find_all do |r|
|
120
|
+
r[0] == key
|
121
|
+
end
|
122
|
+
|
123
|
+
# return just the single result if theres just one,
|
124
|
+
# else take all the fields in the csv and build an array
|
125
|
+
if result.length > 0
|
126
|
+
if result[0].length == 2
|
127
|
+
val = result[0][1].to_s
|
128
|
+
|
129
|
+
# parse %{}'s in the CSV into local variables using lookupvar()
|
130
|
+
while val =~ /%\{(.+?)\}/
|
131
|
+
val.gsub!(/%\{#{$1}\}/, lookupvar($1))
|
132
|
+
end
|
133
|
+
|
134
|
+
desired = val
|
135
|
+
elsif result[0].length > 1
|
136
|
+
length = result[0].length
|
137
|
+
cells = result[0][1,length]
|
138
|
+
|
139
|
+
# Individual cells in a CSV result are a weird data type and throws
|
140
|
+
# puppets yaml parsing, so just map it all to plain old strings
|
141
|
+
desired = cells.map do |c|
|
142
|
+
# parse %{}'s in the CSV into local variables using lookupvar()
|
143
|
+
while c =~ /%\{(.+?)\}/
|
144
|
+
c.gsub!(/%\{#{$1}\}/, lookupvar($1))
|
145
|
+
end
|
146
|
+
|
147
|
+
c.to_s
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
desired || default or raise Puppet::ParseError, "No match found for '#{key}' in any data file during extlookup()"
|
156
|
+
end
|
157
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
Puppet::Parser::Functions::newfunction(:inline_template, :type => :rvalue, :doc =>
|
2
|
-
"Evaluate a template string and return its value. See
|
3
|
-
|
4
|
-
if multiple template strings are specified, their
|
5
|
-
and returned as the output of the function.") do |vals|
|
6
|
-
|
2
|
+
"Evaluate a template string and return its value. See
|
3
|
+
[the templating docs](http://docs.puppetlabs.com/guides/templating.html) for
|
4
|
+
more information. Note that if multiple template strings are specified, their
|
5
|
+
output is all concatenated and returned as the output of the function.") do |vals|
|
6
|
+
|
7
|
+
require 'erb'
|
7
8
|
|
8
9
|
vals.collect do |string|
|
9
10
|
# Use a wrapper, so the template can't get access to the full
|
@@ -5,7 +5,7 @@ Puppet::Parser::Functions::newfunction(:realize, :doc => "Make a virtual object
|
|
5
5
|
when you want to know the name of the virtual object and don't want to
|
6
6
|
bother with a full collection. It is slightly faster than a collection,
|
7
7
|
and, of course, is a bit shorter. You must pass the object using a
|
8
|
-
reference; e.g.:
|
8
|
+
reference; e.g.: `realize User[luke]`." ) do |vals|
|
9
9
|
coll = Puppet::Parser::Collector.new(self, :nomatter, nil, nil, :virtual)
|
10
10
|
vals = [vals] unless vals.is_a?(Array)
|
11
11
|
coll.resources = vals.flatten
|
@@ -6,37 +6,37 @@ module Puppet::Parser::Functions
|
|
6
6
|
:doc => "
|
7
7
|
Perform regexp replacement on a string or array of strings.
|
8
8
|
|
9
|
-
|
9
|
+
* *Parameters* (in order):
|
10
10
|
|
11
|
-
|
11
|
+
_target_ The string or array of strings to operate on. If an array, the replacement will be performed on each of the elements in the array, and the return value will be an array.
|
12
12
|
|
13
|
-
|
13
|
+
_regexp_ The regular expression matching the target string. If you want it anchored at the start and or end of the string, you must do that with ^ and $ yourself.
|
14
14
|
|
15
|
-
|
15
|
+
_replacement_ Replacement string. Can contain back references to what was matched using \\0, \\1, and so on.
|
16
16
|
|
17
|
-
|
17
|
+
_flags_ Optional. String of single letter flags for how the regexp is interpreted:
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
- *E* Extended regexps
|
20
|
+
- *I* Ignore case in regexps
|
21
|
+
- *M* Multiline regexps
|
22
|
+
- *G* Global replacement; all occurrences of the regexp in each target string will be replaced. Without this, only the first occurrence will be replaced.
|
23
23
|
|
24
|
-
|
24
|
+
_lang_ Optional. How to handle multibyte characters. A single-character string with the following values:
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
- *N* None
|
27
|
+
- *E* EUC
|
28
|
+
- *S* SJIS
|
29
|
+
- *U* UTF-8
|
30
30
|
|
31
|
-
|
31
|
+
* *Examples*
|
32
32
|
|
33
|
-
Get the third octet from the node's IP address
|
33
|
+
Get the third octet from the node's IP address:
|
34
34
|
|
35
|
-
|
35
|
+
$i3 = regsubst($ipaddress,'^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$','\\3')
|
36
36
|
|
37
|
-
Put angle brackets around each octet in the node's IP address
|
37
|
+
Put angle brackets around each octet in the node's IP address:
|
38
38
|
|
39
|
-
|
39
|
+
$x = regsubst($ipaddress, '([0-9]+)', '<\\1>', 'G')
|
40
40
|
") \
|
41
41
|
do |args|
|
42
42
|
unless args.length.between?(3, 5)
|
@@ -12,9 +12,8 @@ relationships between classes. This function is a superset of the
|
|
12
12
|
class depends on the required class.
|
13
13
|
|
14
14
|
Warning: using require in place of include can lead to unwanted dependency cycles.
|
15
|
-
|
16
|
-
|
17
|
-
between File[/foo] and Service[foo]::
|
15
|
+
|
16
|
+
For instance the following manifest, with 'require' instead of 'include' would produce a nasty dependence cycle, because notify imposes a before between File[/foo] and Service[foo]:
|
18
17
|
|
19
18
|
class myservice {
|
20
19
|
service { foo: ensure => running }
|
@@ -5,7 +5,7 @@ module Puppet::Parser::Functions
|
|
5
5
|
|
6
6
|
:doc => "Perform printf-style formatting of text.
|
7
7
|
|
8
|
-
The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the
|
8
|
+
The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the `Kernel::sprintf` function in Ruby for all the details.") do |args|
|
9
9
|
raise Puppet::ParseError, 'sprintf() needs at least one argument' if args.length < 1
|
10
10
|
fmt = args.shift
|
11
11
|
return sprintf(fmt, *args)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
Puppet::Parser::Functions::newfunction(:template, :type => :rvalue, :doc =>
|
2
|
-
"Evaluate a template and return its value. See
|
3
|
-
|
2
|
+
"Evaluate a template and return its value. See
|
3
|
+
[the templating docs](http://docs.puppetlabs.com/guides/templating.html) for
|
4
|
+
more information.
|
5
|
+
|
4
6
|
Note that if multiple templates are specified, their output is all
|
5
7
|
concatenated and returned as the output of the function.") do |vals|
|
6
8
|
require 'erb'
|
@@ -3,26 +3,26 @@ require 'puppet/util/package'
|
|
3
3
|
|
4
4
|
Puppet::Parser::Functions::newfunction(
|
5
5
|
:versioncmp, :type => :rvalue,
|
6
|
-
|
6
|
+
|
7
7
|
:doc => "Compares two versions
|
8
8
|
|
9
|
-
Prototype
|
9
|
+
Prototype:
|
10
10
|
|
11
|
-
|
11
|
+
\$result = versioncmp(a, b)
|
12
12
|
|
13
|
-
|
13
|
+
Where a and b are arbitrary version strings
|
14
14
|
|
15
|
-
This functions returns a number
|
15
|
+
This functions returns a number:
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
* > 0 if version a is greater than version b
|
18
|
+
* == 0 if both version are equals
|
19
|
+
* < 0 if version a is less than version b
|
20
20
|
|
21
|
-
Example
|
21
|
+
Example:
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
if versioncmp('2.6-1', '2.4.5') > 0 {
|
24
|
+
notice('2.6-1 is > than 2.4.5')
|
25
|
+
}
|
26
26
|
|
27
27
|
") do |args|
|
28
28
|
|
data/lib/puppet/parser/lexer.rb
CHANGED
@@ -221,7 +221,7 @@ class Puppet::Parser::Lexer
|
|
221
221
|
TOKENS.add_token :RETURN, "\n", :skip => true, :incr_line => true, :skip_text => true
|
222
222
|
|
223
223
|
TOKENS.add_token :SQUOTE, "'" do |lexer, value|
|
224
|
-
[TOKENS[:STRING], lexer.slurpstring(value).first ]
|
224
|
+
[TOKENS[:STRING], lexer.slurpstring(value,["'"],:ignore_invalid_escapes).first ]
|
225
225
|
end
|
226
226
|
|
227
227
|
DQ_initial_token_types = {'$' => :DQPRE,'"' => :STRING}
|
@@ -483,7 +483,7 @@ class Puppet::Parser::Lexer
|
|
483
483
|
yield [final_token.name, token_value]
|
484
484
|
|
485
485
|
if @previous_token
|
486
|
-
namestack(value) if @previous_token.name == :CLASS
|
486
|
+
namestack(value) if @previous_token.name == :CLASS and value != '{'
|
487
487
|
|
488
488
|
if @previous_token.name == :DEFINE
|
489
489
|
if indefine?
|
@@ -517,24 +517,23 @@ class Puppet::Parser::Lexer
|
|
517
517
|
|
518
518
|
# we've encountered the start of a string...
|
519
519
|
# slurp in the rest of the string and return it
|
520
|
-
|
521
|
-
def slurpstring(terminators)
|
520
|
+
def slurpstring(terminators,escapes=%w{ \\ $ ' " n t s }+["\n"],ignore_invalid_escapes=false)
|
522
521
|
# we search for the next quote that isn't preceded by a
|
523
522
|
# backslash; the caret is there to match empty strings
|
524
523
|
str = @scanner.scan_until(/([^\\]|^)[#{terminators}]/) or lex_error "Unclosed quote after '#{last}' in '#{rest}'"
|
525
524
|
@line += str.count("\n") # literal carriage returns add to the line count.
|
526
525
|
str.gsub!(/\\(.)/) {
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
else
|
535
|
-
Puppet.warning "Unrecognised escape sequence '\\#{ch}'#{file && " in file #{file}"}#{line && " at line #{line}"}"
|
536
|
-
"\\#{ch}"
|
526
|
+
ch = $1
|
527
|
+
if escapes.include? ch
|
528
|
+
case ch
|
529
|
+
when 'n'; "\n"
|
530
|
+
when 't'; "\t"
|
531
|
+
when 's'; " "
|
532
|
+
else ch
|
537
533
|
end
|
534
|
+
else
|
535
|
+
Puppet.warning "Unrecognised escape sequence '\\#{ch}'#{file && " in file #{file}"}#{line && " at line #{line}"}" unless ignore_invalid_escapes
|
536
|
+
"\\#{ch}"
|
538
537
|
end
|
539
538
|
}
|
540
539
|
[ str[0..-2],str[-1,1] ]
|
@@ -64,6 +64,7 @@ class Puppet::Parser::Resource < Puppet::Resource
|
|
64
64
|
|
65
65
|
# Retrieve the associated definition and evaluate it.
|
66
66
|
def evaluate
|
67
|
+
@evaluated = true
|
67
68
|
if klass = resource_type and ! builtin_type?
|
68
69
|
finish
|
69
70
|
return klass.evaluate_code(self)
|
@@ -72,8 +73,6 @@ class Puppet::Parser::Resource < Puppet::Resource
|
|
72
73
|
else
|
73
74
|
self.fail "Cannot find definition #{type}"
|
74
75
|
end
|
75
|
-
ensure
|
76
|
-
@evaluated = true
|
77
76
|
end
|
78
77
|
|
79
78
|
# Mark this resource as both exported and virtual,
|
@@ -103,9 +102,9 @@ class Puppet::Parser::Resource < Puppet::Resource
|
|
103
102
|
end
|
104
103
|
|
105
104
|
def initialize(*args)
|
105
|
+
raise ArgumentError, "Resources require a scope" unless args.last[:scope]
|
106
106
|
super
|
107
107
|
|
108
|
-
raise ArgumentError, "Resources require a scope" unless scope
|
109
108
|
@source ||= scope.source
|
110
109
|
end
|
111
110
|
|
@@ -141,10 +140,6 @@ class Puppet::Parser::Resource < Puppet::Resource
|
|
141
140
|
self[:name] || self.title
|
142
141
|
end
|
143
142
|
|
144
|
-
def namespaces
|
145
|
-
scope.namespaces
|
146
|
-
end
|
147
|
-
|
148
143
|
# A temporary occasion, until I get paths in the scopes figured out.
|
149
144
|
def path
|
150
145
|
to_s
|