mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
cron: PEP8 compliancy and doc fixes (#30884)
This PR includes: - PEP8 compliancy fixes - Documentation fixes
This commit is contained in:
parent
863fcb5ace
commit
4647713be9
2 changed files with 101 additions and 134 deletions
|
@ -1,27 +1,24 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# (c) 2012, Dane Summers <dsummers@pinedesk.biz>
|
||||
# (c) 2013, Mike Grozak <mike.grozak@gmail.com>
|
||||
# (c) 2013, Patrick Callahan <pmc@patrickcallahan.com>
|
||||
# (c) 2015, Evan Kaufman <evan@digitalflophouse.com>
|
||||
# (c) 2015, Luca Berruti <nadirio@gmail.com>
|
||||
#
|
||||
|
||||
# Copyright: (c) 2012, Dane Summers <dsummers@pinedesk.biz>
|
||||
# Copyright: (c) 2013, Mike Grozak <mike.grozak@gmail.com>
|
||||
# Copyright: (c) 2013, Patrick Callahan <pmc@patrickcallahan.com>
|
||||
# Copyright: (c) 2015, Evan Kaufman <evan@digitalflophouse.com>
|
||||
# Copyright: (c) 2015, Luca Berruti <nadirio@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: cron
|
||||
short_description: Manage cron.d and crontab entries.
|
||||
short_description: Manage cron.d and crontab entries
|
||||
description:
|
||||
- Use this module to manage crontab and environment variables entries. This module allows
|
||||
you to create environment variables and named crontab entries, update, or delete them.
|
||||
|
@ -41,27 +38,21 @@ options:
|
|||
- Description of a crontab entry or, if env is set, the name of environment variable.
|
||||
Required if state=absent. Note that if name is not set and state=present, then a
|
||||
new crontab entry will always be created, regardless of existing ones.
|
||||
default: null
|
||||
required: false
|
||||
user:
|
||||
description:
|
||||
- The specific user whose crontab should be modified.
|
||||
required: false
|
||||
default: root
|
||||
job:
|
||||
description:
|
||||
- The command to execute or, if env is set, the value of environment variable.
|
||||
The command should not contain line breaks.
|
||||
Required if state=present.
|
||||
required: false
|
||||
aliases: ['value']
|
||||
default: null
|
||||
aliases: [ value ]
|
||||
state:
|
||||
description:
|
||||
- Whether to ensure the job or environment variable is present or absent.
|
||||
required: false
|
||||
choices: [ absent, present ]
|
||||
default: present
|
||||
choices: [ "present", "absent" ]
|
||||
cron_file:
|
||||
description:
|
||||
- If specified, uses this file instead of an individual user's crontab.
|
||||
|
@ -70,92 +61,77 @@ options:
|
|||
Many linux distros expect (and some require) the filename portion to consist solely
|
||||
of upper- and lower-case letters, digits, underscores, and hyphens.
|
||||
To use the C(cron_file) parameter you must specify the C(user) as well.
|
||||
required: false
|
||||
default: null
|
||||
backup:
|
||||
description:
|
||||
- If set, create a backup of the crontab before it is modified.
|
||||
The location of the backup is returned in the C(backup_file) variable by this module.
|
||||
required: false
|
||||
choices: [ "yes", "no" ]
|
||||
default: no
|
||||
type: bool
|
||||
default: 'no'
|
||||
minute:
|
||||
description:
|
||||
- Minute when the job should run ( 0-59, *, */2, etc )
|
||||
required: false
|
||||
default: "*"
|
||||
hour:
|
||||
description:
|
||||
- Hour when the job should run ( 0-23, *, */2, etc )
|
||||
required: false
|
||||
default: "*"
|
||||
day:
|
||||
description:
|
||||
- Day of the month the job should run ( 1-31, *, */2, etc )
|
||||
required: false
|
||||
default: "*"
|
||||
aliases: [ "dom" ]
|
||||
aliases: [ dom ]
|
||||
month:
|
||||
description:
|
||||
- Month of the year the job should run ( 1-12, *, */2, etc )
|
||||
required: false
|
||||
default: "*"
|
||||
weekday:
|
||||
description:
|
||||
- Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
|
||||
required: false
|
||||
default: "*"
|
||||
aliases: [ "dow" ]
|
||||
aliases: [ dow ]
|
||||
reboot:
|
||||
description:
|
||||
- If the job should be run at reboot. This option is deprecated. Users should use special_time.
|
||||
version_added: "1.0"
|
||||
required: false
|
||||
type: bool
|
||||
default: "no"
|
||||
choices: [ "yes", "no" ]
|
||||
special_time:
|
||||
description:
|
||||
- Special time specification nickname.
|
||||
choices: [ reboot, yearly, annually, monthly, weekly, daily, hourly ]
|
||||
version_added: "1.3"
|
||||
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
|
||||
- If the job should be disabled (commented out) in the crontab.
|
||||
- Only has effect if C(state=present).
|
||||
type: bool
|
||||
default: 'no'
|
||||
version_added: "2.0"
|
||||
required: false
|
||||
default: false
|
||||
env:
|
||||
description:
|
||||
- If set, manages a crontab's environment variable. New variables are added on top of crontab.
|
||||
"name" and "value" parameters are the name and the value of environment variable.
|
||||
version_added: "2.1"
|
||||
required: false
|
||||
type: bool
|
||||
default: "no"
|
||||
choices: [ "yes", "no" ]
|
||||
version_added: "2.1"
|
||||
insertafter:
|
||||
description:
|
||||
- Used with C(state=present) and C(env). If specified, the environment variable will be
|
||||
inserted after the declaration of specified environment variable.
|
||||
version_added: "2.1"
|
||||
required: false
|
||||
default: null
|
||||
insertbefore:
|
||||
description:
|
||||
- Used with C(state=present) and C(env). If specified, the environment variable will be
|
||||
inserted before the declaration of specified environment variable.
|
||||
version_added: "2.1"
|
||||
required: false
|
||||
default: null
|
||||
requirements:
|
||||
- cron
|
||||
author:
|
||||
- "Dane Summers (@dsummersl)"
|
||||
- 'Mike Grozak'
|
||||
- 'Patrick Callahan'
|
||||
- 'Evan Kaufman (@EvanK)'
|
||||
- 'Luca Berruti (@lberruti)'
|
||||
- Dane Summers (@dsummersl)
|
||||
- Mike Grozak
|
||||
- Patrick Callahan
|
||||
- Evan Kaufman (@EvanK)
|
||||
- Luca Berruti (@lberruti)
|
||||
"""
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -454,7 +430,6 @@ class CronTab(object):
|
|||
else:
|
||||
return "%s%s %s %s %s %s %s" % (disable_prefix, minute, hour, day, month, weekday, job)
|
||||
|
||||
|
||||
def get_jobnames(self):
|
||||
jobnames = []
|
||||
|
||||
|
@ -547,9 +522,6 @@ class CronTab(object):
|
|||
return "%s %s %s" % (CRONCMD, user, pipes.quote(path))
|
||||
|
||||
|
||||
|
||||
#==================================================
|
||||
|
||||
def main():
|
||||
# The following example playbooks:
|
||||
#
|
||||
|
@ -573,32 +545,29 @@ def main():
|
|||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
name=dict(required=False),
|
||||
user=dict(required=False),
|
||||
job=dict(required=False, aliases=['value']),
|
||||
cron_file=dict(required=False),
|
||||
state=dict(default='present', choices=['present', 'absent']),
|
||||
backup=dict(default=False, type='bool'),
|
||||
minute=dict(default='*'),
|
||||
hour=dict(default='*'),
|
||||
day=dict(aliases=['dom'], default='*'),
|
||||
month=dict(default='*'),
|
||||
weekday=dict(aliases=['dow'], default='*'),
|
||||
reboot=dict(required=False, default=False, type='bool'),
|
||||
special_time=dict(required=False,
|
||||
default=None,
|
||||
choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"],
|
||||
type='str'),
|
||||
disabled=dict(default=False, type='bool'),
|
||||
env=dict(required=False, type='bool'),
|
||||
insertafter=dict(required=False),
|
||||
insertbefore=dict(required=False),
|
||||
name=dict(type='str'),
|
||||
user=dict(type='str'),
|
||||
job=dict(type='str', aliases=['value']),
|
||||
cron_file=dict(type='str'),
|
||||
state=dict(type='str', default='present', choices=['present', 'absent']),
|
||||
backup=dict(type='bool', default=False),
|
||||
minute=dict(type='str', default='*'),
|
||||
hour=dict(type='str', default='*'),
|
||||
day=dict(type='str', default='*', aliases=['dom']),
|
||||
month=dict(type='str', default='*'),
|
||||
weekday=dict(type='str', default='*', aliases=['dow']),
|
||||
reboot=dict(type='bool', default=False),
|
||||
special_time=dict(type='str', choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"]),
|
||||
disabled=dict(type='bool', default=False),
|
||||
env=dict(type='bool'),
|
||||
insertafter=dict(type='str'),
|
||||
insertbefore=dict(type='str'),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
mutually_exclusive=[
|
||||
['reboot', 'special_time'],
|
||||
['insertafter', 'insertbefore'],
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
name = module.params['name']
|
||||
|
@ -627,8 +596,8 @@ def main():
|
|||
if cron_file:
|
||||
cron_file_basename = os.path.basename(cron_file)
|
||||
if not re.search(r'^[A-Z0-9_-]+$', cron_file_basename, re.I):
|
||||
warnings.append('Filename portion of cron_file ("%s") should consist' % cron_file_basename
|
||||
+ ' solely of upper- and lower-case letters, digits, underscores, and hyphens')
|
||||
warnings.append('Filename portion of cron_file ("%s") should consist' % cron_file_basename +
|
||||
' solely of upper- and lower-case letters, digits, underscores, and hyphens')
|
||||
|
||||
# Ensure all files generated are only writable by the owning user. Primarily relevant for the cron_file option.
|
||||
os.umask(int('022', 8))
|
||||
|
@ -675,7 +644,6 @@ def main():
|
|||
(backuph, backup_file) = tempfile.mkstemp(prefix='crontab')
|
||||
crontab.write(backup_file)
|
||||
|
||||
|
||||
if crontab.cron_file and not name and not do_install:
|
||||
if module._diff:
|
||||
diff['after'] = ''
|
||||
|
|
|
@ -404,7 +404,6 @@ lib/ansible/modules/storage/zfs/zfs.py
|
|||
lib/ansible/modules/system/aix_inittab.py
|
||||
lib/ansible/modules/system/at.py
|
||||
lib/ansible/modules/system/capabilities.py
|
||||
lib/ansible/modules/system/cron.py
|
||||
lib/ansible/modules/system/cronvar.py
|
||||
lib/ansible/modules/system/crypttab.py
|
||||
lib/ansible/modules/system/debconf.py
|
||||
|
|
Loading…
Reference in a new issue