From 7c9c8396d18bd2d5e75292ae5e4ac730a690865a Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Sun, 19 Feb 2017 17:51:12 +0100 Subject: [PATCH] cron: don't force changed=True when old crontab was empty The cron module forces changed=True when there was no real change, but the original crontab did not contain a final newline, which is mandatory. When the user has no crontab or the user does not exist at all, crontab -l exits with 1 and the cron module correctly interprets this as "no crontab" and stores the old crontab as "". However this triggers changed=True, even if we're not going to change anything, e.g. when removing a crontab entry from a user who has no crontabs at all. Let's special-case the fact that the old crontab is empty and not force changed=True in that case. (cherry picked from commit 61579aebb2bf18dce76c1c39b33a0d7f33ed7073) --- lib/ansible/modules/system/cron.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/cron.py b/lib/ansible/modules/system/cron.py index ae4b3b27b1e..ac9ee9a4a41 100644 --- a/lib/ansible/modules/system/cron.py +++ b/lib/ansible/modules/system/cron.py @@ -726,7 +726,7 @@ def main(): changed = True # no changes to env/job, but existing crontab needs a terminating newline - if not changed: + if not changed and not crontab.existing == '': if not (crontab.existing.endswith('\r') or crontab.existing.endswith('\n')): changed = True