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