Patch provided by Andrew Forgue
Signed-off-by: James Turnbull <
ja...@lovedthanlost.net>
---
lib/puppet/provider/cron/crontab.rb | 2 +
lib/puppet/util/filetype.rb | 45 +++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb
index 82384d0..6dee2e5 100755
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -3,6 +3,8 @@ require 'puppet/provider/parsedfile'
tab = case Facter.value(:operatingsystem)
when "Solaris"
:suntab
+ when "AIX"
+ :aixtab
else
:crontab
end
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 93c002f..b66a1a1 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -251,4 +251,49 @@ class Puppet::Util::FileType
output_file.delete
end
end
+
+ # Support for AIX crontab with differing ouput from suntab jon crontab command.
+ newfiletype(:aixtab) do
+ # Read a specific @path's cron tab.
+ def read
+ begin
+ output = Puppet::Util.execute(%w{crontab -l}, :uid => @path)
+ return "" if output.include?("You are not authorized to use the cron command")
+ raise Puppet::Error, "User %s not authorized to use cron" % @path if output.include?("You are not authorized to use the cron command")
+ return output
+ rescue => detail
+ raise Puppet::Error, "Could not read crontab for %s: %s" % [@path, detail]
+ end
+ end
+
+ # Remove a specific @path's cron tab.
+ def remove
+ begin
+ Puppet::Util.execute(%w{crontab -r}, :uid => @path)
+ rescue => detail
+ raise Puppet::Error, "Could not remove crontab for %s: %s" % [@path, detail]
+ end
+ end
+
+ # Overwrite a specific @path's cron tab; must be passed the @path name
+ # and the text with which to create the cron tab.
+ def write(text)
+ puts text
+ require "tempfile"
+ output_file = Tempfile.new("puppet")
+ fh = output_file.open
+ fh.print text
+ fh.close
+
+ # We have to chown the stupid file to the user.
+ File.chown(Puppet::Util.uid(@path), nil, output_file.path)
+
+ begin
+ Puppet::Util.execute(["crontab", output_file.path], :uid => @path)
+ rescue => detail
+ raise Puppet::Error, "Could not write crontab for %s: %s" % [@path, detail]
+ end
+ output_file.delete
+ end
+ end
end
--
1.6.2.5