diff options
author | Andrew Forgue <andrew.forgue@gmail.com> | 2009-11-23 17:58:13 -0500 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-12-02 13:24:38 +1100 |
commit | 01c98f6a196d37d346ccb34863502409da212f8d (patch) | |
tree | c6a022f9e0ec3d10a2fee999f0af51246baa676d /lib/puppet | |
parent | f7c5ceb325da912e05457cd69eb74e03f541cc9f (diff) | |
download | puppet-01c98f6a196d37d346ccb34863502409da212f8d.tar.gz puppet-01c98f6a196d37d346ccb34863502409da212f8d.tar.xz puppet-01c98f6a196d37d346ccb34863502409da212f8d.zip |
Fixed #2798 - Correct issue with crontab provider on AIX
Clean up AIX crontab type:
- The return "" if output.include?(...) prevented the
raise from ever being reached.
- Ensure the temp file is deleted after feeding it
to cron.
- Prevent dumping of the new crontab to STDOUT.
Signed-off-by: Andrew Forgue <andrew.forgue@gmail.com>
Diffstat (limited to 'lib/puppet')
-rwxr-xr-x | lib/puppet/provider/cron/crontab.rb | 2 | ||||
-rwxr-xr-x | lib/puppet/util/filetype.rb | 46 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb index 82384d09d..6dee2e515 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 93c002fa9..8e8b8dd5c 100755 --- a/lib/puppet/util/filetype.rb +++ b/lib/puppet/util/filetype.rb @@ -251,4 +251,50 @@ class Puppet::Util::FileType output_file.delete end end + + # Support for AIX crontab with output different than suntab's crontab command. + newfiletype(:aixtab) do + # Read a specific @path's cron tab. + def read + begin + output = Puppet::Util.execute(%w{crontab -l}, :uid => @path) + if output.include?("You are not authorized to use the cron command") + raise Puppet::Error, "User %s not authorized to use cron" % @path + end + 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) + 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] + ensure + output_file.delete + end + end + end end |