forked from ansible/ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
# (c) 2012, Dane Summers <[email protected]> | ||
# (c) 2013, Mike Grozak <[email protected]> | ||
# (c) 2013, Patrick Callahan <[email protected]> | ||
# (c) 2015, Evan Kaufman <[email protected]> | ||
# | ||
# This file is part of Ansible | ||
# | ||
|
@@ -116,10 +117,16 @@ | |
required: false | ||
default: null | ||
choices: [ "reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly" ] | ||
disabled: | ||
description: | ||
- If the job should be disabled (commented out) in the crontab. Only has effect if state=present | ||
version_added: "1.9" | ||
required: false | ||
default: false | ||
requirements: | ||
- cron | ||
author: "Dane Summers (@dsummersl)" | ||
updates: [ 'Mike Grozak', 'Patrick Callahan' ] | ||
updates: [ 'Mike Grozak', 'Patrick Callahan', 'Evan Kaufman' ] | ||
""" | ||
|
||
EXAMPLES = ''' | ||
|
@@ -291,17 +298,22 @@ def find_job(self, name): | |
|
||
return [] | ||
|
||
def get_cron_job(self,minute,hour,day,month,weekday,job,special): | ||
def get_cron_job(self,minute,hour,day,month,weekday,job,special,disabled): | ||
if disabled: | ||
disable_prefix = '#' | ||
else: | ||
disable_prefix = '' | ||
|
||
if special: | ||
if self.cron_file: | ||
return "@%s %s %s" % (special, self.user, job) | ||
return "%s@%s %s %s" % (disable_prefix, special, self.user, job) | ||
else: | ||
return "@%s %s" % (special, job) | ||
return "%s@%s %s" % (disable_prefix, special, job) | ||
else: | ||
if self.cron_file: | ||
return "%s %s %s %s %s %s %s" % (minute,hour,day,month,weekday,self.user,job) | ||
return "%s%s %s %s %s %s %s %s" % (disable_prefix,minute,hour,day,month,weekday,self.user,job) | ||
else: | ||
return "%s %s %s %s %s %s" % (minute,hour,day,month,weekday,job) | ||
return "%s%s %s %s %s %s %s" % (disable_prefix,minute,hour,day,month,weekday,job) | ||
|
||
return None | ||
|
||
|
@@ -414,7 +426,8 @@ def main(): | |
special_time=dict(required=False, | ||
default=None, | ||
choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"], | ||
type='str') | ||
type='str'), | ||
disabled=dict(default=False, type='bool') | ||
), | ||
supports_check_mode = False, | ||
) | ||
|
@@ -432,6 +445,7 @@ def main(): | |
weekday = module.params['weekday'] | ||
reboot = module.params['reboot'] | ||
special_time = module.params['special_time'] | ||
disabled = module.params['disabled'] | ||
do_install = state == 'present' | ||
|
||
changed = False | ||
|
@@ -482,7 +496,7 @@ def main(): | |
changed = crontab.remove_job_file() | ||
module.exit_json(changed=changed,cron_file=cron_file,state=state) | ||
|
||
job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time) | ||
job = crontab.get_cron_job(minute, hour, day, month, weekday, job, special_time, disabled) | ||
old_job = crontab.find_job(name) | ||
|
||
if do_install: | ||
|