Add disabled option to cron module
This commit is contained in:
parent
a886690309
commit
b3495e238c
1 changed files with 22 additions and 8 deletions
|
@ -4,6 +4,7 @@
|
||||||
# (c) 2012, Dane Summers <dsummers@pinedesk.biz>
|
# (c) 2012, Dane Summers <dsummers@pinedesk.biz>
|
||||||
# (c) 2013, Mike Grozak <mike.grozak@gmail.com>
|
# (c) 2013, Mike Grozak <mike.grozak@gmail.com>
|
||||||
# (c) 2013, Patrick Callahan <pmc@patrickcallahan.com>
|
# (c) 2013, Patrick Callahan <pmc@patrickcallahan.com>
|
||||||
|
# (c) 2015, Evan Kaufman <evan@digitalflophouse.com>
|
||||||
#
|
#
|
||||||
# This file is part of Ansible
|
# This file is part of Ansible
|
||||||
#
|
#
|
||||||
|
@ -116,10 +117,16 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
choices: [ "reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly" ]
|
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:
|
requirements:
|
||||||
- cron
|
- cron
|
||||||
author: "Dane Summers (@dsummersl)"
|
author: "Dane Summers (@dsummersl)"
|
||||||
updates: [ 'Mike Grozak', 'Patrick Callahan' ]
|
updates: [ 'Mike Grozak', 'Patrick Callahan', 'Evan Kaufman' ]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -291,17 +298,22 @@ class CronTab(object):
|
||||||
|
|
||||||
return []
|
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 special:
|
||||||
if self.cron_file:
|
if self.cron_file:
|
||||||
return "@%s %s %s" % (special, self.user, job)
|
return "%s@%s %s %s" % (disable_prefix, special, self.user, job)
|
||||||
else:
|
else:
|
||||||
return "@%s %s" % (special, job)
|
return "%s@%s %s" % (disable_prefix, special, job)
|
||||||
else:
|
else:
|
||||||
if self.cron_file:
|
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:
|
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
|
return None
|
||||||
|
|
||||||
|
@ -414,7 +426,8 @@ def main():
|
||||||
special_time=dict(required=False,
|
special_time=dict(required=False,
|
||||||
default=None,
|
default=None,
|
||||||
choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"],
|
choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"],
|
||||||
type='str')
|
type='str'),
|
||||||
|
disabled=dict(default=False, type='bool')
|
||||||
),
|
),
|
||||||
supports_check_mode = False,
|
supports_check_mode = False,
|
||||||
)
|
)
|
||||||
|
@ -432,6 +445,7 @@ def main():
|
||||||
weekday = module.params['weekday']
|
weekday = module.params['weekday']
|
||||||
reboot = module.params['reboot']
|
reboot = module.params['reboot']
|
||||||
special_time = module.params['special_time']
|
special_time = module.params['special_time']
|
||||||
|
disabled = module.params['disabled']
|
||||||
do_install = state == 'present'
|
do_install = state == 'present'
|
||||||
|
|
||||||
changed = False
|
changed = False
|
||||||
|
@ -482,7 +496,7 @@ def main():
|
||||||
changed = crontab.remove_job_file()
|
changed = crontab.remove_job_file()
|
||||||
module.exit_json(changed=changed,cron_file=cron_file,state=state)
|
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)
|
old_job = crontab.find_job(name)
|
||||||
|
|
||||||
if do_install:
|
if do_install:
|
||||||
|
|
Loading…
Reference in a new issue