puppet 2.6.6 → 2.6.7

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.

Files changed (140) hide show
  1. data/CHANGELOG +107 -1
  2. data/README.queueing +1 -1
  3. data/Rakefile +1 -1
  4. data/conf/solaris/smf/svc-puppetd +0 -2
  5. data/conf/solaris/smf/svc-puppetmasterd +0 -2
  6. data/examples/etc/init.d/sleeper +0 -2
  7. data/examples/modules/sample-module/README.txt +2 -2
  8. data/ext/puppetstoredconfigclean.rb +1 -1
  9. data/install.rb +20 -25
  10. data/lib/puppet.rb +1 -1
  11. data/lib/puppet/application/agent.rb +2 -2
  12. data/lib/puppet/application/apply.rb +2 -2
  13. data/lib/puppet/application/cert.rb +27 -11
  14. data/lib/puppet/application/filebucket.rb +1 -1
  15. data/lib/puppet/application/inspect.rb +1 -1
  16. data/lib/puppet/application/kick.rb +2 -2
  17. data/lib/puppet/application/master.rb +1 -1
  18. data/lib/puppet/application/queue.rb +2 -2
  19. data/lib/puppet/configurer/downloader.rb +1 -0
  20. data/lib/puppet/configurer/plugin_handler.rb +8 -1
  21. data/lib/puppet/daemon.rb +1 -1
  22. data/lib/puppet/defaults.rb +18 -2
  23. data/lib/puppet/external/nagios.rb +0 -2
  24. data/lib/puppet/external/nagios/base.rb +0 -2
  25. data/lib/puppet/indirector/facts/inventory_active_record.rb +97 -0
  26. data/lib/puppet/indirector/facts/rest.rb +2 -0
  27. data/lib/puppet/indirector/facts/yaml.rb +75 -0
  28. data/lib/puppet/indirector/indirection.rb +1 -0
  29. data/lib/puppet/module.rb +1 -1
  30. data/lib/puppet/network/http/api/v1.rb +3 -4
  31. data/lib/puppet/network/http/compression.rb +4 -1
  32. data/lib/puppet/network/http/handler.rb +1 -1
  33. data/lib/puppet/network/rest_authconfig.rb +1 -1
  34. data/lib/puppet/node/facts.rb +29 -0
  35. data/lib/puppet/parser/ast/collection.rb +5 -4
  36. data/lib/puppet/parser/ast/leaf.rb +1 -1
  37. data/lib/puppet/parser/functions/regsubst.rb +7 -14
  38. data/lib/puppet/parser/functions/split.rb +7 -7
  39. data/lib/puppet/parser/grammar.ra +2 -4
  40. data/lib/puppet/parser/lexer.rb +4 -1
  41. data/lib/puppet/parser/parser.rb +2062 -1976
  42. data/lib/puppet/parser/parser_support.rb +3 -3
  43. data/lib/puppet/provider/computer/computer.rb +1 -3
  44. data/lib/puppet/provider/mount.rb +12 -16
  45. data/lib/puppet/provider/mount/parsed.rb +67 -8
  46. data/lib/puppet/provider/parsedfile.rb +3 -1
  47. data/lib/puppet/provider/service/daemontools.rb +6 -6
  48. data/lib/puppet/provider/service/gentoo.rb +0 -2
  49. data/lib/puppet/provider/service/launchd.rb +11 -8
  50. data/lib/puppet/provider/service/runit.rb +4 -4
  51. data/lib/puppet/provider/user/useradd.rb +6 -1
  52. data/lib/puppet/rails/database/004_add_inventory_service_tables.rb +36 -0
  53. data/lib/puppet/rails/database/schema.rb +17 -0
  54. data/lib/puppet/rails/fact_name.rb +0 -2
  55. data/lib/puppet/rails/fact_value.rb +0 -2
  56. data/lib/puppet/rails/inventory_fact.rb +5 -0
  57. data/lib/puppet/rails/inventory_node.rb +25 -0
  58. data/lib/puppet/reference/configuration.rb +1 -1
  59. data/lib/puppet/reference/metaparameter.rb +1 -1
  60. data/lib/puppet/reports/store.rb +4 -1
  61. data/lib/puppet/resource.rb +39 -25
  62. data/lib/puppet/type.rb +5 -5
  63. data/lib/puppet/type/augeas.rb +4 -4
  64. data/lib/puppet/type/computer.rb +5 -1
  65. data/lib/puppet/type/exec.rb +3 -1
  66. data/lib/puppet/type/file.rb +3 -1
  67. data/lib/puppet/type/file/content.rb +13 -15
  68. data/lib/puppet/type/file/ensure.rb +11 -17
  69. data/lib/puppet/type/file/selcontext.rb +16 -0
  70. data/lib/puppet/type/file/target.rb +14 -1
  71. data/lib/puppet/type/k5login.rb +0 -2
  72. data/lib/puppet/type/macauthorization.rb +4 -1
  73. data/lib/puppet/type/mcx.rb +4 -1
  74. data/lib/puppet/type/mount.rb +37 -21
  75. data/lib/puppet/type/package.rb +5 -1
  76. data/lib/puppet/type/schedule.rb +20 -20
  77. data/lib/puppet/type/selmodule.rb +3 -1
  78. data/lib/puppet/type/ssh_authorized_key.rb +5 -1
  79. data/lib/puppet/type/user.rb +14 -1
  80. data/lib/puppet/type/zfs.rb +3 -1
  81. data/lib/puppet/type/zone.rb +3 -1
  82. data/lib/puppet/type/zpool.rb +7 -5
  83. data/lib/puppet/util.rb +5 -0
  84. data/lib/puppet/util/command_line.rb +1 -1
  85. data/lib/puppet/util/execution.rb +4 -5
  86. data/lib/puppet/util/execution_stub.rb +26 -0
  87. data/lib/puppet/util/monkey_patches.rb +21 -0
  88. data/lib/puppet/util/rdoc/code_objects.rb +39 -0
  89. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +18 -0
  90. data/lib/puppet/util/rdoc/parser.rb +5 -3
  91. data/lib/puppet/util/settings.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +7 -0
  93. data/spec/integration/provider/mount_spec.rb +151 -0
  94. data/spec/integration/type/file_spec.rb +32 -29
  95. data/spec/spec_helper.rb +2 -0
  96. data/spec/unit/application/agent_spec.rb +3 -7
  97. data/spec/unit/application/apply_spec.rb +17 -2
  98. data/spec/unit/application/cert_spec.rb +54 -14
  99. data/spec/unit/application/filebucket_spec.rb +1 -1
  100. data/spec/unit/application/queue_spec.rb +1 -5
  101. data/spec/unit/configurer/downloader_spec.rb +22 -10
  102. data/spec/unit/daemon_spec.rb +1 -5
  103. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +163 -0
  104. data/spec/unit/indirector/facts/yaml_spec.rb +216 -2
  105. data/spec/unit/indirector/queue_spec.rb +3 -0
  106. data/spec/unit/module_spec.rb +2 -2
  107. data/spec/unit/network/handler/fileserver_spec.rb +1 -1
  108. data/spec/unit/network/http/api/v1_spec.rb +28 -0
  109. data/spec/unit/network/http/compression_spec.rb +1 -1
  110. data/spec/unit/network/http/handler_spec.rb +7 -4
  111. data/spec/unit/node/facts_spec.rb +24 -0
  112. data/spec/unit/parser/ast/collection_spec.rb +16 -12
  113. data/spec/unit/parser/lexer_spec.rb +16 -0
  114. data/spec/unit/parser/parser_spec.rb +35 -2
  115. data/spec/unit/provider/mount/parsed_spec.rb +199 -114
  116. data/spec/unit/provider/mount_spec.rb +54 -53
  117. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -0
  118. data/spec/unit/provider/user/user_role_add_spec.rb +1 -0
  119. data/spec/unit/provider/user/useradd_spec.rb +43 -3
  120. data/spec/unit/reports/store_spec.rb +1 -1
  121. data/spec/unit/resource_spec.rb +39 -13
  122. data/spec/unit/type/file/content_spec.rb +38 -137
  123. data/spec/unit/type/file/selinux_spec.rb +5 -0
  124. data/spec/unit/type/mount_spec.rb +167 -122
  125. data/spec/unit/type/user_spec.rb +4 -0
  126. data/spec/unit/type_spec.rb +12 -1
  127. data/spec/unit/util/execution_spec.rb +49 -0
  128. data/spec/unit/util/execution_stub_spec.rb +35 -0
  129. data/spec/unit/util/rdoc/parser_spec.rb +15 -3
  130. data/spec/unit/util/settings_spec.rb +11 -2
  131. data/tasks/rake/git_workflow.rake +1 -1
  132. data/test/Rakefile +0 -2
  133. data/test/data/providers/mount/parsed/aix.mount +7 -0
  134. data/test/data/providers/mount/parsed/darwin.mount +6 -0
  135. data/test/data/providers/mount/parsed/hpux.mount +17 -0
  136. data/test/data/providers/mount/parsed/linux.mount +5 -0
  137. data/test/data/providers/mount/parsed/solaris.mount +6 -0
  138. data/test/data/types/mount/linux.fstab +1 -0
  139. data/test/data/types/mount/solaris.fstab +1 -0
  140. metadata +18 -4
@@ -119,7 +119,17 @@ module Puppet
119
119
  :node_terminus => ["plain", "Where to find information about nodes."],
120
120
  :catalog_terminus => ["compiler", "Where to get node catalogs. This is useful to change if, for instance,
121
121
  you'd like to pre-compile catalogs and store them in memcached or some other easily-accessed store."],
122
- :facts_terminus => [Puppet.application_name.to_s == "master" ? 'yaml' : 'facter', "The node facts terminus."],
122
+ :facts_terminus => {
123
+ :default => Puppet.application_name.to_s == "master" ? 'yaml' : 'facter',
124
+ :desc => "The node facts terminus.",
125
+ :hook => proc do |value|
126
+ require 'puppet/node/facts'
127
+ if value.to_s == "rest"
128
+ Puppet::Node::Facts.cache_class = :yaml
129
+ end
130
+ end
131
+ },
132
+ :inventory_terminus => [ "$facts_terminus", "Should usually be the same as the facts terminus" ],
123
133
  :httplog => { :default => "$logdir/http.log",
124
134
  :owner => "root",
125
135
  :mode => 0640,
@@ -582,11 +592,17 @@ module Puppet
582
592
  end
583
593
  },
584
594
  :report_server => ["$server",
585
- "The server to which to send transaction reports."
595
+ "The server to send transaction reports to."
586
596
  ],
587
597
  :report_port => ["$masterport",
588
598
  "The port to communicate with the report_server."
589
599
  ],
600
+ :inventory_server => ["$server",
601
+ "The server to send facts to."
602
+ ],
603
+ :inventory_port => ["$masterport",
604
+ "The port to communicate with the inventory_server."
605
+ ],
590
606
  :report => [false,
591
607
  "Whether to send reports after every transaction."
592
608
  ],
@@ -3,8 +3,6 @@
3
3
  #--------------------
4
4
  # A script to retrieve hosts from ldap and create an importable
5
5
  # cfservd file from them
6
- #
7
- # $Id: nagios.rb,v 1.3 2004/06/09 20:32:46 luke Exp $
8
6
 
9
7
  require 'digest/md5'
10
8
  #require 'ldap'
@@ -470,5 +470,3 @@ class Nagios::Base
470
470
  end
471
471
 
472
472
  end
473
-
474
- # $Id$
@@ -0,0 +1,97 @@
1
+ require 'puppet/rails'
2
+ require 'puppet/rails/inventory_node'
3
+ require 'puppet/rails/inventory_fact'
4
+ require 'puppet/indirector/active_record'
5
+
6
+ class Puppet::Node::Facts::InventoryActiveRecord < Puppet::Indirector::ActiveRecord
7
+ def find(request)
8
+ node = Puppet::Rails::InventoryNode.find_by_name(request.key)
9
+ return nil unless node
10
+ facts = Puppet::Node::Facts.new(node.name, node.facts_to_hash)
11
+ facts.timestamp = node.timestamp
12
+ facts
13
+ end
14
+
15
+ def save(request)
16
+ facts = request.instance
17
+ node = Puppet::Rails::InventoryNode.find_by_name(request.key) || Puppet::Rails::InventoryNode.create(:name => request.key, :timestamp => facts.timestamp)
18
+ node.timestamp = facts.timestamp
19
+
20
+ ActiveRecord::Base.transaction do
21
+ Puppet::Rails::InventoryFact.delete_all(:node_id => node.id)
22
+ # We don't want to save internal values as facts, because those are
23
+ # metadata that belong on the node
24
+ facts.values.each do |name,value|
25
+ next if name.to_s =~ /^_/
26
+ node.facts.build(:name => name, :value => value)
27
+ end
28
+ node.save
29
+ end
30
+ end
31
+
32
+ def search(request)
33
+ return [] unless request.options
34
+ matching_nodes = []
35
+ fact_names = []
36
+ fact_filters = Hash.new {|h,k| h[k] = []}
37
+ meta_filters = Hash.new {|h,k| h[k] = []}
38
+ request.options.each do |key,value|
39
+ type, name, operator = key.to_s.split(".")
40
+ operator ||= "eq"
41
+ if type == "facts"
42
+ fact_filters[operator] << [name,value]
43
+ elsif type == "meta" and name == "timestamp"
44
+ meta_filters[operator] << [name,value]
45
+ end
46
+ end
47
+
48
+ matching_nodes = nodes_matching_fact_filters(fact_filters) + nodes_matching_meta_filters(meta_filters)
49
+
50
+ # to_a because [].inject == nil
51
+ matching_nodes.inject {|nodes,this_set| nodes & this_set}.to_a.sort
52
+ end
53
+
54
+ private
55
+
56
+ def nodes_matching_fact_filters(fact_filters)
57
+ node_sets = []
58
+ fact_filters['eq'].each do |name,value|
59
+ node_sets << Puppet::Rails::InventoryNode.has_fact_with_value(name,value).map {|node| node.name}
60
+ end
61
+ fact_filters['ne'].each do |name,value|
62
+ node_sets << Puppet::Rails::InventoryNode.has_fact_without_value(name,value).map {|node| node.name}
63
+ end
64
+ {
65
+ 'gt' => '>',
66
+ 'lt' => '<',
67
+ 'ge' => '>=',
68
+ 'le' => '<='
69
+ }.each do |operator_name,operator|
70
+ fact_filters[operator_name].each do |name,value|
71
+ facts = Puppet::Rails::InventoryFact.find_by_sql(["SELECT inventory_facts.value, inventory_nodes.name AS node_name
72
+ FROM inventory_facts INNER JOIN inventory_nodes
73
+ ON inventory_facts.node_id = inventory_nodes.id
74
+ WHERE inventory_facts.name = ?", name])
75
+ node_sets << facts.select {|fact| fact.value.to_f.send(operator, value.to_f)}.map {|fact| fact.node_name}
76
+ end
77
+ end
78
+ node_sets
79
+ end
80
+
81
+ def nodes_matching_meta_filters(meta_filters)
82
+ node_sets = []
83
+ {
84
+ 'eq' => '=',
85
+ 'ne' => '!=',
86
+ 'gt' => '>',
87
+ 'lt' => '<',
88
+ 'ge' => '>=',
89
+ 'le' => '<='
90
+ }.each do |operator_name,operator|
91
+ meta_filters[operator_name].each do |name,value|
92
+ node_sets << Puppet::Rails::InventoryNode.find(:all, :select => "name", :conditions => ["timestamp #{operator} ?", value]).map {|node| node.name}
93
+ end
94
+ end
95
+ node_sets
96
+ end
97
+ end
@@ -3,4 +3,6 @@ require 'puppet/indirector/rest'
3
3
 
4
4
  class Puppet::Node::Facts::Rest < Puppet::Indirector::REST
5
5
  desc "Find and save facts about nodes over HTTP via REST."
6
+ use_server_setting(:inventory_server)
7
+ use_port_setting(:inventory_port)
6
8
  end
@@ -4,4 +4,79 @@ require 'puppet/indirector/yaml'
4
4
  class Puppet::Node::Facts::Yaml < Puppet::Indirector::Yaml
5
5
  desc "Store client facts as flat files, serialized using YAML, or
6
6
  return deserialized facts from disk."
7
+
8
+ def search(request)
9
+ node_names = []
10
+ Dir.glob(yaml_dir_path).each do |file|
11
+ facts = YAML.load_file(file)
12
+ node_names << facts.name if node_matches?(facts, request.options)
13
+ end
14
+ node_names
15
+ end
16
+
17
+ private
18
+
19
+ # Return the path to a given node's file.
20
+ def yaml_dir_path
21
+ base = Puppet.run_mode.master? ? Puppet[:yamldir] : Puppet[:clientyamldir]
22
+ File.join(base, 'facts', '*.yaml')
23
+ end
24
+
25
+ def node_matches?(facts, options)
26
+ options.each do |key, value|
27
+ type, name, operator = key.to_s.split(".")
28
+ operator ||= 'eq'
29
+
30
+ return false unless node_matches_option?(type, name, operator, value, facts)
31
+ end
32
+ return true
33
+ end
34
+
35
+ def node_matches_option?(type, name, operator, value, facts)
36
+ case type
37
+ when "meta"
38
+ case name
39
+ when "timestamp"
40
+ compare_timestamp(operator, facts.timestamp, Time.parse(value))
41
+ end
42
+ when "facts"
43
+ compare_facts(operator, facts.values[name], value)
44
+ end
45
+ end
46
+
47
+ def compare_facts(operator, value1, value2)
48
+ return false unless value1
49
+
50
+ case operator
51
+ when "eq"
52
+ value1.to_s == value2.to_s
53
+ when "le"
54
+ value1.to_f <= value2.to_f
55
+ when "ge"
56
+ value1.to_f >= value2.to_f
57
+ when "lt"
58
+ value1.to_f < value2.to_f
59
+ when "gt"
60
+ value1.to_f > value2.to_f
61
+ when "ne"
62
+ value1.to_s != value2.to_s
63
+ end
64
+ end
65
+
66
+ def compare_timestamp(operator, value1, value2)
67
+ case operator
68
+ when "eq"
69
+ value1 == value2
70
+ when "le"
71
+ value1 <= value2
72
+ when "ge"
73
+ value1 >= value2
74
+ when "lt"
75
+ value1 < value2
76
+ when "gt"
77
+ value1 > value2
78
+ when "ne"
79
+ value1 != value2
80
+ end
81
+ end
7
82
  end
@@ -248,6 +248,7 @@ class Puppet::Indirector::Indirection
248
248
  if result = terminus.search(request)
249
249
  raise Puppet::DevError, "Search results from terminus #{terminus.name} are not an array" unless result.is_a?(Array)
250
250
  result.each do |instance|
251
+ next unless instance.respond_to? :expiration
251
252
  instance.expiration ||= self.expiration
252
253
  end
253
254
  return result
@@ -191,7 +191,7 @@ class Puppet::Module
191
191
 
192
192
  def backward_compatible_plugins_dir
193
193
  if dir = File.join(path, "plugins") and FileTest.exist?(dir)
194
- warning "using the deprecated 'plugins' directory for ruby extensions; please move to 'lib'"
194
+ Puppet.warning "using the deprecated 'plugins' directory for ruby extensions; please move to 'lib'"
195
195
  return dir
196
196
  else
197
197
  return File.join(path, "lib")
@@ -60,13 +60,12 @@ module Puppet::Network::HTTP::API::V1
60
60
  # fix to not need this, and our goal is to move away from the complication
61
61
  # that leads to the fix being too long.
62
62
  return :singular if indirection == "facts"
63
-
64
- # "status" really is singular
65
63
  return :singular if indirection == "status"
64
+ return :plural if indirection == "inventory"
66
65
 
67
- result = (indirection =~ /s$/) ? :plural : :singular
66
+ result = (indirection =~ /s$|_search$/) ? :plural : :singular
68
67
 
69
- indirection.sub!(/s$/, '') if result
68
+ indirection.sub!(/s$|_search$|es$/, '')
70
69
 
71
70
  result
72
71
  end
@@ -75,7 +75,10 @@ module Puppet::Network::HTTP::Compression
75
75
  # in this case, we try with a verbatim (no header)
76
76
  # deflater.
77
77
  @uncompressor = Zlib::Inflate.new
78
- retry if @first
78
+ if @first then
79
+ @first = false
80
+ retry
81
+ end
79
82
  raise
80
83
  end
81
84
 
@@ -131,7 +131,7 @@ module Puppet::Network::HTTP::Handler
131
131
  def do_search(indirection_request, request, response)
132
132
  result = indirection_request.model.search(indirection_request.key, indirection_request.to_hash)
133
133
 
134
- if result.nil? or (result.is_a?(Array) and result.empty?)
134
+ if result.nil?
135
135
  return do_exception(response, "Could not find instances in #{indirection_request.indirection_name} with '#{indirection_request.key}'", 404)
136
136
  end
137
137
 
@@ -61,7 +61,7 @@ module Puppet
61
61
  def insert_default_acl
62
62
  DEFAULT_ACL.each do |acl|
63
63
  unless rights[acl[:acl]]
64
- Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) acl because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none where found in '#{@file}'")}"
64
+ Puppet.info "Inserting default '#{acl[:acl]}'(#{acl[:authenticated] ? "auth" : "non-auth"}) ACL because #{( !exists? ? "#{Puppet[:rest_authconfig]} doesn't exist" : "none were found in '#{@file}'")}"
65
65
  mk_acl(acl)
66
66
  end
67
67
  end
@@ -1,12 +1,17 @@
1
+ require 'time'
2
+
1
3
  require 'puppet/node'
2
4
  require 'puppet/indirector'
3
5
 
6
+ require 'puppet/util/pson'
7
+
4
8
  # Manage a given node's facts. This either accepts facts and stores them, or
5
9
  # returns facts for a given node.
6
10
  class Puppet::Node::Facts
7
11
  # Set up indirection, so that nodes can be looked for in
8
12
  # the node sources.
9
13
  extend Puppet::Indirector
14
+ extend Puppet::Util::Pson
10
15
 
11
16
  # We want to expire any cached nodes if the facts are saved.
12
17
  module NodeExpirer
@@ -54,6 +59,30 @@ class Puppet::Node::Facts
54
59
  strip_internal == other.send(:strip_internal)
55
60
  end
56
61
 
62
+ def timestamp=(time)
63
+ self.values[:_timestamp] = time
64
+ end
65
+
66
+ def timestamp
67
+ self.values[:_timestamp]
68
+ end
69
+
70
+ def self.from_pson(data)
71
+ result = new(data['name'], data['values'])
72
+ result.timestamp = Time.parse(data['timestamp'])
73
+ result.expiration = Time.parse(data['expiration'])
74
+ result
75
+ end
76
+
77
+ def to_pson(*args)
78
+ {
79
+ 'expiration' => expiration,
80
+ 'name' => name,
81
+ 'timestamp' => timestamp,
82
+ 'values' => strip_internal,
83
+ }.to_pson(*args)
84
+ end
85
+
57
86
  private
58
87
 
59
88
  # Add internal data to the facts for storage.
@@ -16,6 +16,7 @@ class Puppet::Parser::AST
16
16
  str, code = query && query.safeevaluate(scope)
17
17
 
18
18
  resource_type = scope.find_resource_type(@type)
19
+ fail "Resource type #{@type} doesn't exist" unless resource_type
19
20
  newcoll = Puppet::Parser::Collector.new(scope, resource_type.name, str, code, self.form)
20
21
 
21
22
  scope.compiler.add_collection(newcoll)
@@ -26,10 +27,10 @@ class Puppet::Parser::AST
26
27
  params = @override.collect { |param| param.safeevaluate(scope) }
27
28
  newcoll.add_override(
28
29
  :parameters => params,
29
- :file => @file,
30
- :line => @line,
31
- :source => scope.source,
32
- :scope => scope
30
+ :file => @file,
31
+ :line => @line,
32
+ :source => scope.source,
33
+ :scope => scope
33
34
  )
34
35
  end
35
36
 
@@ -67,7 +67,7 @@ class Puppet::Parser::AST
67
67
  end
68
68
 
69
69
  def to_s
70
- "concat(#{@value.join(',')})"
70
+ "#{@value.map { |s| s.to_s.gsub(/^"(.*)"$/, '\1') }.join}"
71
71
  end
72
72
  end
73
73
 
@@ -4,25 +4,18 @@ module Puppet::Parser::Functions
4
4
  :regsubst, :type => :rvalue,
5
5
 
6
6
  :doc => "
7
- Perform regexp replacement on a string or array of strings.
7
+ Perform regexp replacement on a string or array of strings.
8
8
 
9
9
  * *Parameters* (in order):
10
-
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
-
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
-
15
- _replacement_ Replacement string. Can contain back references to what was matched using \\0, \\1, and so on.
16
-
17
- _flags_ Optional. String of single letter flags for how the regexp is interpreted:
18
-
10
+ * _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.
11
+ * _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.
12
+ * _replacement_ Replacement string. Can contain backreferences to what was matched using \\0 (whole match), \\1 (first set of parentheses), and so on.
13
+ * _flags_ Optional. String of single letter flags for how the regexp is interpreted:
19
14
  - *E* Extended regexps
20
15
  - *I* Ignore case in regexps
21
16
  - *M* Multiline regexps
22
17
  - *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
-
24
- _lang_ Optional. How to handle multibyte characters. A single-character string with the following values:
25
-
18
+ * _encoding_ Optional. How to handle multibyte characters. A single-character string with the following values:
26
19
  - *N* None
27
20
  - *E* EUC
28
21
  - *S* SJIS
@@ -32,7 +25,7 @@ module Puppet::Parser::Functions
32
25
 
33
26
  Get the third octet from the node's IP address:
34
27
 
35
- $i3 = regsubst($ipaddress,'^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$','\\3')
28
+ $i3 = regsubst($ipaddress,'^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$','\\3')
36
29
 
37
30
  Put angle brackets around each octet in the node's IP address:
38
31
 
@@ -6,21 +6,21 @@ module Puppet::Parser::Functions
6
6
  :doc => "\
7
7
  Split a string variable into an array using the specified split regexp.
8
8
 
9
- Usage:
9
+ *Example:*
10
10
 
11
11
  $string = 'v1.v2:v3.v4'
12
12
  $array_var1 = split($string, ':')
13
13
  $array_var2 = split($string, '[.]')
14
14
  $array_var3 = split($string, '[.:]')
15
15
 
16
- $array_var1 now holds the result ['v1.v2', 'v3.v4'],
17
- while $array_var2 holds ['v1', 'v2:v3', 'v4'], and
18
- $array_var3 holds ['v1', 'v2', 'v3', 'v4'].
16
+ `$array_var1` now holds the result `['v1.v2', 'v3.v4']`,
17
+ while `$array_var2` holds `['v1', 'v2:v3', 'v4']`, and
18
+ `$array_var3` holds `['v1', 'v2', 'v3', 'v4']`.
19
19
 
20
- Note that in the second example, we split on a string that contains
21
- a regexp meta-character (.), and that needs protection. A simple
20
+ Note that in the second example, we split on a literal string that contains
21
+ a regexp meta-character (.), which must be escaped. A simple
22
22
  way to do that for a single character is to enclose it in square
23
- brackets.") do |args|
23
+ brackets; a backslash will also escape a single character.") do |args|
24
24
 
25
25
  raise Puppet::ParseError, ("split(): wrong number of arguments (#{args.length}; must be 2)") if args.length != 2
26
26