From b7713830dc76aad3bf25897dc843ce090129d7d6 Mon Sep 17 00:00:00 2001 From: Andrew Klaus Date: Tue, 27 Oct 2020 23:49:14 -0600 Subject: [PATCH] OpenBSD Syspatch: Apply patches by default. Minor module cleanup (#360) * Apply patches by default. Other minor cleanup * syspatch: Adding changelog and deprecating redundant apply argument * Update changelogs/fragments/360_syspatch_apply_patches_by_default.yml Co-authored-by: Felix Fontein * Apply suggestions from code review Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- .../360_syspatch_apply_patches_by_default.yml | 4 +++ plugins/modules/system/syspatch.py | 28 +++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 changelogs/fragments/360_syspatch_apply_patches_by_default.yml diff --git a/changelogs/fragments/360_syspatch_apply_patches_by_default.yml b/changelogs/fragments/360_syspatch_apply_patches_by_default.yml new file mode 100644 index 0000000000..2bc4262c94 --- /dev/null +++ b/changelogs/fragments/360_syspatch_apply_patches_by_default.yml @@ -0,0 +1,4 @@ +bugfixes: + - syspatch - fix bug where not setting ``apply=true`` would result in error (https://github.com/ansible-collections/community.general/pull/360). +deprecated_features: + - syspatch - deprecate the redundant ``apply`` argument (https://github.com/ansible-collections/community.general/pull/360). diff --git a/plugins/modules/system/syspatch.py b/plugins/modules/system/syspatch.py index 1a26f07b4f..4d3ade639b 100644 --- a/plugins/modules/system/syspatch.py +++ b/plugins/modules/system/syspatch.py @@ -1,12 +1,12 @@ #!/usr/bin/python -# Copyright: (c) 2019, Andrew Klaus +# Copyright: (c) 2019-2020, Andrew Klaus # 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 -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: syspatch @@ -14,18 +14,18 @@ short_description: Manage OpenBSD system patches description: - - "Manage OpenBSD system patches using syspatch" + - "Manage OpenBSD system patches using syspatch." options: apply: description: - - Apply all available system patches - default: False - required: false + - Apply all available system patches. + - By default, apply all patches. + - Deprecated. Will be removed in community.general 3.0.0. + default: yes revert: description: - - Revert system patches - required: false + - Revert system patches. type: str choices: [ all, one ] @@ -63,17 +63,17 @@ rc: returned: always type: int stdout: - description: syspatch standard output + description: syspatch standard output. returned: always type: str sample: "001_rip6cksum" stderr: - description: syspatch standard error + description: syspatch standard error. returned: always type: str sample: "syspatch: need root privileges" reboot_needed: - description: Whether or not a reboot is required after an update + description: Whether or not a reboot is required after an update. returned: always type: bool sample: True @@ -85,7 +85,7 @@ from ansible.module_utils.basic import AnsibleModule def run_module(): # define available arguments/parameters a user can pass to the module module_args = dict( - apply=dict(type='bool'), + apply=dict(type='bool', default=True, removed_in_version='3.0.0', removed_from_collection='community.general'), revert=dict(type='str', choices=['all', 'one']) ) @@ -142,10 +142,10 @@ def syspatch_run(module): # http://openbsd-archive.7691.n7.nabble.com/Warning-applying-latest-syspatch-td354250.html if rc != 0 and err != 'ln: /usr/X11R6/bin/X: No such file or directory\n': module.fail_json(msg="Command %s failed rc=%d, out=%s, err=%s" % (cmd, rc, out, err)) - elif out.lower().find('create unique kernel') > 0: + elif out.lower().find('create unique kernel') >= 0: # Kernel update applied reboot_needed = True - elif out.lower().find('syspatch updated itself') > 0: + elif out.lower().find('syspatch updated itself') >= 0: warnings.append('Syspatch was updated. Please run syspatch again.') # If no stdout, then warn user