|
|
|
@ -311,9 +311,15 @@ class CronTab:
|
|
|
|
if backup_file:
|
|
|
|
if backup_file:
|
|
|
|
fileh = open(backup_file, 'wb')
|
|
|
|
fileh = open(backup_file, 'wb')
|
|
|
|
elif self.cron_file:
|
|
|
|
elif self.cron_file:
|
|
|
|
|
|
|
|
try:
|
|
|
|
fileh = open(self.b_cron_file, 'wb')
|
|
|
|
fileh = open(self.b_cron_file, 'wb')
|
|
|
|
|
|
|
|
except (OSError, FileNotFoundError) as ex:
|
|
|
|
|
|
|
|
self.module.fail_json(msg=f'Unable to open {self.cron_file} for writing: {to_native(ex)}')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|
|
|
|
try:
|
|
|
|
filed, path = tempfile.mkstemp(prefix='crontab')
|
|
|
|
filed, path = tempfile.mkstemp(prefix='crontab')
|
|
|
|
|
|
|
|
except OSError as ex:
|
|
|
|
|
|
|
|
self.module.fail_json(msg=f'Unable to create temporary file for writing crontab as {ex}')
|
|
|
|
os.chmod(path, S_IRWU_RWG_RWO)
|
|
|
|
os.chmod(path, S_IRWU_RWG_RWO)
|
|
|
|
fileh = os.fdopen(filed, 'wb')
|
|
|
|
fileh = os.fdopen(filed, 'wb')
|
|
|
|
|
|
|
|
|
|
|
|
@ -662,7 +668,10 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
# if requested make a backup before making a change
|
|
|
|
# if requested make a backup before making a change
|
|
|
|
if backup and not module.check_mode:
|
|
|
|
if backup and not module.check_mode:
|
|
|
|
|
|
|
|
try:
|
|
|
|
(dummy, backup_file) = tempfile.mkstemp(prefix='crontab')
|
|
|
|
(dummy, backup_file) = tempfile.mkstemp(prefix='crontab')
|
|
|
|
|
|
|
|
except OSError as ex:
|
|
|
|
|
|
|
|
module.fail_json(msg=f"Unable to create temporary file for backup: {to_native(ex)}")
|
|
|
|
crontab.write(backup_file)
|
|
|
|
crontab.write(backup_file)
|
|
|
|
|
|
|
|
|
|
|
|
if env:
|
|
|
|
if env:
|
|
|
|
|