summaryrefslogtreecommitdiff
path: root/lib/puppet/type/file_line.rb
diff options
context:
space:
mode:
authorJeff McCune <jeff@puppetlabs.com>2012-08-14 10:08:41 -0700
committerJeff McCune <jeff@puppetlabs.com>2012-08-14 10:08:41 -0700
commit77262494b368c115da2a71c4a53e2a9bd21ff2aa (patch)
tree0ded58647c134dafa32604725b010f32a465164f /lib/puppet/type/file_line.rb
parentf30885118843f2eef15c048fe2cb504d7eaf8f77 (diff)
parenta06c0d8115892a74666676b50d4282df9850a119 (diff)
downloadpuppet-stdlib-77262494b368c115da2a71c4a53e2a9bd21ff2aa.tar.gz
puppet-stdlib-77262494b368c115da2a71c4a53e2a9bd21ff2aa.tar.bz2
Merge branch 'feature/2.4.x/backport_file_line_match_pr75' into 2.4.x
* feature/2.4.x/backport_file_line_match_pr75: Add support for a 'match' parameter to file_line
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