diff options
| author | Bryan Jen <bryan.jen@gmail.com> | 2015-04-09 11:30:22 -0700 | 
|---|---|---|
| committer | Bryan Jen <bryan.jen@gmail.com> | 2015-04-09 14:44:52 -0700 | 
| commit | 35303ce0f7cf66feb7499d9671a7d2121a0f52b1 (patch) | |
| tree | 1993ac17877969c539bfc2873d3812a599afeec2 | |
| parent | 8fba5c058ba344421796cceca8f96dffcba0a4fc (diff) | |
| download | puppet-stdlib-35303ce0f7cf66feb7499d9671a7d2121a0f52b1.tar.gz puppet-stdlib-35303ce0f7cf66feb7499d9671a7d2121a0f52b1.tar.bz2  | |
file_line honors after if match not found.
| -rw-r--r-- | lib/puppet/provider/file_line/ruby.rb | 9 | 
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index ae1a8b3..a1acab8 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -34,13 +34,22 @@ Puppet::Type.type(:file_line).provide(:ruby) do    def handle_create_with_match()      regex = resource[:match] ? Regexp.new(resource[:match]) : nil +    regex_after = resource[:after] ? Regexp.new(resource[:after]) : nil      match_count = count_matches(regex) +      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|          fh.puts(regex.match(l) ? resource[:line] : l) +        if (match_count == 0 and regex_after) +          if regex_after.match(l) +            fh.puts(resource[:line]) +            match_count += 1 #Increment match_count to indicate that the new line has been inserted. +          end +        end        end        if (match_count == 0)  | 
