From bcc08564e75caea1240b2b1c044acf0b233189f0 Mon Sep 17 00:00:00 2001 From: Jim Richardson Date: Sun, 3 Nov 2013 17:43:51 -0800 Subject: [PATCH 1/2] fix for https://github.com/ansible/ansible/issues/4795 Incorrect changed result in cron module. Report changed=False if no cron is removed:wq --- library/system/cron | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/system/cron b/library/system/cron index 3bf43b7d562..f0fd0c2a27e 100644 --- a/library/system/cron +++ b/library/system/cron @@ -464,8 +464,10 @@ def main(): crontab.write(backup_file) if crontab.cron_file and not do_install: - crontab.remove_job_file() - changed = True + if crontab.remove_job_file(): + changed = True + else: + changed = False module.exit_json(changed=changed,cron_file=cron_file,state=state) job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time) From bbfe11fc1eb3d331d2613fcecc8cdb579ed91f0a Mon Sep 17 00:00:00 2001 From: Jim Richardson Date: Mon, 4 Nov 2013 14:14:53 -0800 Subject: [PATCH 2/2] return True/False from remove_job_file() revised fix for https://github.com/ansible/ansible/issues/4795 --- library/system/cron | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/library/system/cron b/library/system/cron index f0fd0c2a27e..23f8efe09b2 100644 --- a/library/system/cron +++ b/library/system/cron @@ -266,9 +266,10 @@ class CronTab(object): def remove_job_file(self): try: os.unlink(self.cron_file) + return True except OSError, e: # cron file does not exist - return + return False except: raise CronTabError("Unexpected error:", sys.exc_info()[0]) @@ -464,10 +465,7 @@ def main(): crontab.write(backup_file) if crontab.cron_file and not do_install: - if crontab.remove_job_file(): - changed = True - else: - changed = False + changed = crontab.remove_job_file() module.exit_json(changed=changed,cron_file=cron_file,state=state) job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time)