diff --git a/library/cron b/library/cron index ebd3b6cb078..73eca78903b 100644 --- a/library/cron +++ b/library/cron @@ -132,6 +132,7 @@ updates: Mike Grozak import re import tempfile +import os def get_jobs_file(module, user, tmpfile, cron_file): if cron_file: @@ -143,11 +144,19 @@ def get_jobs_file(module, user, tmpfile, cron_file): def install_jobs(module, user, tmpfile, cron_file): if cron_file: - cmd = "ln -f %s /etc/cron.d/%s" % (tmpfile, cron_file) + cron_file = '/etc/cron.d/%s' % cron_file + try: + module.atomic_replace(tmpfile, cron_file) + except (OSError, IOError), e: + return (1, "", str(e)) + except: + return (1, "", str(e)) + else: + return (0, "", "") + else: cmd = "crontab %s %s" % (user, tmpfile) - - return module.run_command(cmd) + return module.run_command(cmd) def get_jobs(tmpfile): lines = open(tmpfile).read().splitlines()