mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #1318 from dsummersl/cron24
fixed cron library so backups are python2.4 compatible
This commit is contained in:
commit
20a7227056
1 changed files with 5 additions and 6 deletions
11
library/cron
11
library/cron
|
@ -251,11 +251,11 @@ def main():
|
||||||
(rc, out, err) = get_jobs_file(user,tmpfile.name)
|
(rc, out, err) = get_jobs_file(user,tmpfile.name)
|
||||||
if rc != 0 and rc != 1: # 1 can mean that there are no jobs.
|
if rc != 0 and rc != 1: # 1 can mean that there are no jobs.
|
||||||
module.fail_json(msg=err)
|
module.fail_json(msg=err)
|
||||||
backupfile = tempfile.NamedTemporaryFile(prefix='crontab',delete=False)
|
(handle,backupfile) = tempfile.mkstemp(prefix='crontab')
|
||||||
(rc, out, err) = get_jobs_file(user,backupfile.name)
|
(rc, out, err) = get_jobs_file(user,backupfile)
|
||||||
if rc != 0 and rc != 1:
|
if rc != 0 and rc != 1:
|
||||||
module.fail_json(msg=err)
|
module.fail_json(msg=err)
|
||||||
old_job = find_job(name,backupfile.name)
|
old_job = find_job(name,backupfile)
|
||||||
if do_install:
|
if do_install:
|
||||||
if len(old_job) == 0:
|
if len(old_job) == 0:
|
||||||
(rc, out, err) = add_job(name,job,tmpfile.name)
|
(rc, out, err) = add_job(name,job,tmpfile.name)
|
||||||
|
@ -271,7 +271,7 @@ def main():
|
||||||
module.fail_json(msg=err)
|
module.fail_json(msg=err)
|
||||||
if changed:
|
if changed:
|
||||||
if backup:
|
if backup:
|
||||||
module.backup_local(backupfile.name)
|
module.backup_local(backupfile)
|
||||||
(rc, out, err) = install_jobs(user,tmpfile.name)
|
(rc, out, err) = install_jobs(user,tmpfile.name)
|
||||||
if (rc != 0):
|
if (rc != 0):
|
||||||
module.fail_json(msg=err)
|
module.fail_json(msg=err)
|
||||||
|
@ -280,11 +280,10 @@ def main():
|
||||||
for j in get_jobs(tmpfile.name):
|
for j in get_jobs(tmpfile.name):
|
||||||
jobnames.append(j[0])
|
jobnames.append(j[0])
|
||||||
tmpfile.close()
|
tmpfile.close()
|
||||||
backupfile.close()
|
|
||||||
if not backup:
|
if not backup:
|
||||||
module.exit_json(changed=changed,jobs=jobnames)
|
module.exit_json(changed=changed,jobs=jobnames)
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=changed,jobs=jobnames,backup=backupfile.name)
|
module.exit_json(changed=changed,jobs=jobnames,backup=backupfile)
|
||||||
|
|
||||||
# include magic from lib/ansible/module_common.py
|
# include magic from lib/ansible/module_common.py
|
||||||
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
||||||
|
|
Loading…
Reference in a new issue