summaryrefslogtreecommitdiff
path: root/lib/puppet/type/file_line.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/type/file_line.rb')
-rw-r--r--lib/puppet/type/file_line.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index f6fe1d0..6b35902 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -32,6 +32,11 @@ Puppet::Type.newtype(:file_line) do
desc 'An arbitrary name used as the identity of the resource.'
end
+ newparam(:match) do
+ desc 'An optional regular expression to run against existing lines in the file;\n' +
+ 'if a match is found, we replace that line rather than adding a new line.'
+ end
+
newparam(:line) do
desc 'The line to be appended to the file located by the path parameter.'
end
@@ -49,5 +54,12 @@ Puppet::Type.newtype(:file_line) do
unless self[:line] and self[:path]
raise(Puppet::Error, "Both line and path are required attributes")
end
+
+ if (self[:match])
+ unless Regexp.new(self[:match]).match(self[:line])
+ raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter")
+ end
+ end
+
end
end