[cron] Remove deprecated features (#74197)

Change:
- Require name always
- Drop 'reboot' parameter in favor of 'special_time: reboot'

Test Plan:
- CI

Tickets:
- fixes #74132

Signed-off-by: Rick Elrod <rick@elrod.me>
This commit is contained in:
Rick Elrod 2021-04-08 14:50:27 -05:00 committed by GitHub
parent d5ce6e6bed
commit d7df8a4484
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 36 deletions

View file

@ -0,0 +1,3 @@
minor_changes:
- "cron - ``name`` is now a required parameter always"
- "cron - ``reboot`` parameter has been dropped in favor of ``special_time: reboot``"

View file

@ -37,7 +37,8 @@ No notable changes
Modules Modules
======= =======
No notable changes * ``cron`` now requires ``name`` to be specified in all cases.
* ``cron`` no longer allows a ``reboot`` parameter. Use ``special_time: reboot`` instead.
Modules removed Modules removed

View file

@ -33,11 +33,9 @@ options:
name: name:
description: description:
- 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 I(state=absent). - This parameter is always required as of ansible-core 2.12.
- Note that if name is not set and I(state=present), then a
new crontab entry will always be created, regardless of existing ones.
- This parameter will always be required in future releases.
type: str type: str
required: yes
user: user:
description: description:
- The specific user whose crontab should be modified. - The specific user whose crontab should be modified.
@ -98,12 +96,6 @@ options:
type: str type: str
default: "*" default: "*"
aliases: [ dow ] aliases: [ dow ]
reboot:
description:
- If the job should be run at reboot. This option is deprecated. Users should use I(special_time).
version_added: "1.0"
type: bool
default: no
special_time: special_time:
description: description:
- Special time specification nickname. - Special time specification nickname.
@ -562,7 +554,7 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
name=dict(type='str'), name=dict(type='str', required=True),
user=dict(type='str'), user=dict(type='str'),
job=dict(type='str', aliases=['value']), job=dict(type='str', aliases=['value']),
cron_file=dict(type='str'), cron_file=dict(type='str'),
@ -573,7 +565,6 @@ def main():
day=dict(type='str', default='*', aliases=['dom']), day=dict(type='str', default='*', aliases=['dom']),
month=dict(type='str', default='*'), month=dict(type='str', default='*'),
weekday=dict(type='str', default='*', aliases=['dow']), 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"]), special_time=dict(type='str', choices=["reboot", "yearly", "annually", "monthly", "weekly", "daily", "hourly"]),
disabled=dict(type='bool', default=False), disabled=dict(type='bool', default=False),
env=dict(type='bool', default=False), env=dict(type='bool', default=False),
@ -582,7 +573,6 @@ def main():
), ),
supports_check_mode=True, supports_check_mode=True,
mutually_exclusive=[ mutually_exclusive=[
['reboot', 'special_time'],
['insertafter', 'insertbefore'], ['insertafter', 'insertbefore'],
], ],
) )
@ -598,7 +588,6 @@ def main():
day = module.params['day'] day = module.params['day']
month = module.params['month'] month = module.params['month']
weekday = module.params['weekday'] weekday = module.params['weekday']
reboot = module.params['reboot']
special_time = module.params['special_time'] special_time = module.params['special_time']
disabled = module.params['disabled'] disabled = module.params['disabled']
env = module.params['env'] env = module.params['env']
@ -622,17 +611,6 @@ def main():
module.debug('cron instantiated - name: "%s"' % name) module.debug('cron instantiated - name: "%s"' % name)
if not name:
module.deprecate(
msg="The 'name' parameter will be required in future releases.",
version='2.12', collection_name='ansible.builtin'
)
if reboot:
module.deprecate(
msg="The 'reboot' parameter will be removed in future releases. Use 'special_time' option instead.",
version='2.12', collection_name='ansible.builtin'
)
if module._diff: if module._diff:
diff = dict() diff = dict()
diff['before'] = crontab.n_existing diff['before'] = crontab.n_existing
@ -646,15 +624,12 @@ def main():
# --- user input validation --- # --- user input validation ---
if env and not name: if special_time and \
module.fail_json(msg="You must specify 'name' while working with environment variables (env=yes)")
if (special_time or reboot) and \
(True in [(x != '*') for x in [minute, hour, day, month, weekday]]): (True in [(x != '*') for x in [minute, hour, day, month, weekday]]):
module.fail_json(msg="You must specify time and date fields or special time.") module.fail_json(msg="You must specify time and date fields or special time.")
# cannot support special_time on solaris # cannot support special_time on solaris
if (special_time or reboot) and platform.system() == 'SunOS': if special_time and platform.system() == 'SunOS':
module.fail_json(msg="Solaris does not support special_time=... or @reboot") module.fail_json(msg="Solaris does not support special_time=... or @reboot")
if cron_file and do_install: if cron_file and do_install:
@ -667,9 +642,6 @@ def main():
if (insertafter or insertbefore) and not env and do_install: if (insertafter or insertbefore) and not env and do_install:
module.fail_json(msg="Insertafter and insertbefore parameters are valid only with env=yes") module.fail_json(msg="Insertafter and insertbefore parameters are valid only with env=yes")
if reboot:
special_time = "reboot"
# 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:
(backuph, backup_file) = tempfile.mkstemp(prefix='crontab') (backuph, backup_file) = tempfile.mkstemp(prefix='crontab')

View file

@ -91,8 +91,9 @@
- assert: - assert:
that: remove_task_idempotence is not changed that: remove_task_idempotence is not changed
- name: Check that removing a cron task with cron_file and without specifying an user is allowed (#58493) - name: Check that removing a cron task with cron_file and without specifying a user is allowed (#58493)
cron: cron:
name: test cron task
cron_file: unexistent_cron_file cron_file: unexistent_cron_file
state: absent state: absent
register: remove_cron_file register: remove_cron_file

View file

@ -103,7 +103,6 @@ lib/ansible/modules/copy.py pylint:blacklisted-name
lib/ansible/modules/copy.py validate-modules:doc-default-does-not-match-spec lib/ansible/modules/copy.py validate-modules:doc-default-does-not-match-spec
lib/ansible/modules/copy.py validate-modules:nonexistent-parameter-documented lib/ansible/modules/copy.py validate-modules:nonexistent-parameter-documented
lib/ansible/modules/copy.py validate-modules:undocumented-parameter lib/ansible/modules/copy.py validate-modules:undocumented-parameter
lib/ansible/modules/cron.py pylint:ansible-deprecated-version
lib/ansible/modules/dnf.py validate-modules:doc-required-mismatch lib/ansible/modules/dnf.py validate-modules:doc-required-mismatch
lib/ansible/modules/dnf.py validate-modules:parameter-invalid lib/ansible/modules/dnf.py validate-modules:parameter-invalid
lib/ansible/modules/file.py validate-modules:doc-default-does-not-match-spec lib/ansible/modules/file.py validate-modules:doc-default-does-not-match-spec