From d7df8a4484e50b27e921e9fe887dc84c86617e7f Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Thu, 8 Apr 2021 14:50:27 -0500 Subject: [PATCH] [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 --- changelogs/fragments/cron-deprecations.yml | 3 ++ .../porting_guide_core_2.12.rst | 3 +- lib/ansible/modules/cron.py | 38 +++---------------- test/integration/targets/cron/tasks/main.yml | 3 +- test/sanity/ignore.txt | 1 - 5 files changed, 12 insertions(+), 36 deletions(-) create mode 100644 changelogs/fragments/cron-deprecations.yml diff --git a/changelogs/fragments/cron-deprecations.yml b/changelogs/fragments/cron-deprecations.yml new file mode 100644 index 00000000000..2f218fbefac --- /dev/null +++ b/changelogs/fragments/cron-deprecations.yml @@ -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``" diff --git a/docs/docsite/rst/porting_guides/porting_guide_core_2.12.rst b/docs/docsite/rst/porting_guides/porting_guide_core_2.12.rst index ac570d481bc..868597ab7a5 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_core_2.12.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_core_2.12.rst @@ -37,7 +37,8 @@ No notable changes 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 diff --git a/lib/ansible/modules/cron.py b/lib/ansible/modules/cron.py index 2424f5c0655..a84a4bada7f 100644 --- a/lib/ansible/modules/cron.py +++ b/lib/ansible/modules/cron.py @@ -33,11 +33,9 @@ options: name: description: - Description of a crontab entry or, if env is set, the name of environment variable. - - Required if I(state=absent). - - 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. + - This parameter is always required as of ansible-core 2.12. type: str + required: yes user: description: - The specific user whose crontab should be modified. @@ -98,12 +96,6 @@ options: type: str default: "*" 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: description: - Special time specification nickname. @@ -562,7 +554,7 @@ def main(): module = AnsibleModule( argument_spec=dict( - name=dict(type='str'), + name=dict(type='str', required=True), user=dict(type='str'), job=dict(type='str', aliases=['value']), cron_file=dict(type='str'), @@ -573,7 +565,6 @@ def main(): 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', default=False), @@ -582,7 +573,6 @@ def main(): ), supports_check_mode=True, mutually_exclusive=[ - ['reboot', 'special_time'], ['insertafter', 'insertbefore'], ], ) @@ -598,7 +588,6 @@ def main(): day = module.params['day'] month = module.params['month'] weekday = module.params['weekday'] - reboot = module.params['reboot'] special_time = module.params['special_time'] disabled = module.params['disabled'] env = module.params['env'] @@ -622,17 +611,6 @@ def main(): 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: diff = dict() diff['before'] = crontab.n_existing @@ -646,15 +624,12 @@ def main(): # --- user input validation --- - if env and not name: - module.fail_json(msg="You must specify 'name' while working with environment variables (env=yes)") - - if (special_time or reboot) and \ + if special_time and \ (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.") # 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") if cron_file and do_install: @@ -667,9 +642,6 @@ def main(): if (insertafter or insertbefore) and not env and do_install: 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 backup and not module.check_mode: (backuph, backup_file) = tempfile.mkstemp(prefix='crontab') diff --git a/test/integration/targets/cron/tasks/main.yml b/test/integration/targets/cron/tasks/main.yml index 5484072a21e..c5f22b2dd1b 100644 --- a/test/integration/targets/cron/tasks/main.yml +++ b/test/integration/targets/cron/tasks/main.yml @@ -91,8 +91,9 @@ - assert: 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: + name: test cron task cron_file: unexistent_cron_file state: absent register: remove_cron_file diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index cb8a94b0a38..d43bd159fbd 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -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:nonexistent-parameter-documented 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:parameter-invalid lib/ansible/modules/file.py validate-modules:doc-default-does-not-match-spec