Only remove crontabs if they are empty

pull/74497/head
Fabian Klemp 4 years ago
parent 728e43bc59
commit fefda12827

@ -647,18 +647,6 @@ def main():
(backuph, backup_file) = tempfile.mkstemp(prefix='crontab') (backuph, backup_file) = tempfile.mkstemp(prefix='crontab')
crontab.write(backup_file) crontab.write(backup_file)
if crontab.cron_file and not do_install:
if module._diff:
diff['after'] = ''
diff['after_header'] = '/dev/null'
else:
diff = dict()
if module.check_mode:
changed = os.path.isfile(crontab.cron_file)
else:
changed = crontab.remove_job_file()
module.exit_json(changed=changed, cron_file=cron_file, state=state, diff=diff)
if env: if env:
if ' ' in name: if ' ' in name:
module.fail_json(msg="Invalid name for environment variable") module.fail_json(msg="Invalid name for environment variable")
@ -701,6 +689,17 @@ def main():
if len(old_job) > 0: if len(old_job) > 0:
crontab.remove_job(name) crontab.remove_job(name)
changed = True changed = True
if crontab.cron_file and crontab.is_empty():
if module._diff:
diff['after'] = ''
diff['after_header'] = '/dev/null'
else:
diff = dict()
if module.check_mode:
changed = os.path.isfile(crontab.cron_file)
else:
changed = crontab.remove_job_file()
module.exit_json(changed=changed, cron_file=cron_file, state=state, diff=diff)
# no changes to env/job, but existing crontab needs a terminating newline # no changes to env/job, but existing crontab needs a terminating newline
if not changed and crontab.n_existing != '': if not changed and crontab.n_existing != '':

Loading…
Cancel
Save