summaryrefslogtreecommitdiff
path: root/lib/puppet/provider/file_line/ruby.rb
diff options
context:
space:
mode:
authorAlex O'Rielly <aorielly@gmail.com>2013-06-21 17:33:44 -0500
committerAdrien Thebo <git@somethingsinistral.net>2013-07-11 16:25:56 -0700
commit964a9ad6193b0dd243a44ddae1509655fc9e9fb8 (patch)
tree415b40d4bcdf9ffca0513154ed3ffd454107da91 /lib/puppet/provider/file_line/ruby.rb
parentca7633c0e4830edb0dab4dc31609086eb7edba67 (diff)
(#21416) Allow file_line to match multiple lines
Without this commit the file_line type will outright fail if multiple lines match the given regex. This commit allows the file_line type and provider to optionally match and modify all matching lines. Changeset rebased into a single commit by Adrien Thebo <adrien@puppetlabs.com>
Diffstat (limited to 'lib/puppet/provider/file_line/ruby.rb')
-rw-r--r--lib/puppet/provider/file_line/ruby.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index a3219d3..3cb9f6e 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -1,4 +1,3 @@
-
Puppet::Type.type(:file_line).provide(:ruby) do
def exists?
@@ -35,8 +34,8 @@ Puppet::Type.type(:file_line).provide(:ruby) do
def handle_create_with_match()
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
match_count = lines.select { |l| regex.match(l) }.size
- if match_count > 1
- raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
+ if match_count > 1 && resource[:multiple].to_s != 'true'
+ raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
end
File.open(resource[:path], 'w') do |fh|
lines.each do |l|