summaryrefslogtreecommitdiff
path: root/lib/puppet/type
diff options
context:
space:
mode:
authorJeff McCune <jeff@puppetlabs.com>2012-06-10 23:28:13 -0700
committerJeff McCune <jeff@puppetlabs.com>2012-06-10 23:28:13 -0700
commite299ac6212b0468426f971b216447ef6bc679149 (patch)
tree1eb1b72036a9a1b5c6f31b3a5dda63906eb554d5 /lib/puppet/type
parentcf7ac0286043d01aa807743d75574d450536582d (diff)
parent9e0256aabfd58dfce8cff65147722a844f56e006 (diff)
downloadpuppet-stdlib-e299ac6212b0468426f971b216447ef6bc679149.tar.gz
puppet-stdlib-e299ac6212b0468426f971b216447ef6bc679149.tar.bz2
Merge pull request #75 from cprice-puppet/feature/master/regex-support-for-file-line
Add support for a 'match' parameter to file_line
Diffstat (limited to 'lib/puppet/type')
-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