From a9fd9f8982a1f2ff7de3939bb885c9a7d8174439 Mon Sep 17 00:00:00 2001 From: tover99 <101673769+tover99@users.noreply.github.com> Date: Mon, 22 May 2023 06:24:53 +0200 Subject: [PATCH] added handling of zypper exitcode 102: ZYPPER_EXIT_INF_REBOOT_NEEDED (#6534) * added handling of zypper exitcode 102: ZYPPER_EXIT_INF_REBOOT_NEEDED - Returned after a successful installation of a patch which requires reboot of computer. The exitcode 102 will be treated exactly like 0 by the module internally now, and the changed status will be reported correctly. However, since I preserve the rc 102 in the retvals to allow the playbook to react to the requested reboot, the task must still include a "failed_when: zypper_cmd.rc not in [0, 102]" to not fail in this case. * removed trailing whitespaces * added changelogs fragment * Fix typo. Co-authored-by: Alex * Add URL. --------- Co-authored-by: Felix Fontein Co-authored-by: Alex --- changelogs/fragments/6534-zypper-exitcode-102-handled.yaml | 2 ++ plugins/modules/zypper.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6534-zypper-exitcode-102-handled.yaml diff --git a/changelogs/fragments/6534-zypper-exitcode-102-handled.yaml b/changelogs/fragments/6534-zypper-exitcode-102-handled.yaml new file mode 100644 index 0000000000..baed17cae5 --- /dev/null +++ b/changelogs/fragments/6534-zypper-exitcode-102-handled.yaml @@ -0,0 +1,2 @@ +bugfixes: + - zypper - added handling of zypper exitcode 102. Changed state is set correctly now and rc 102 is still preserved to be evaluated by the playbook (https://github.com/ansible-collections/community.general/pull/6534). \ No newline at end of file diff --git a/plugins/modules/zypper.py b/plugins/modules/zypper.py index 9ba5555e20..b47131d3d1 100644 --- a/plugins/modules/zypper.py +++ b/plugins/modules/zypper.py @@ -324,10 +324,11 @@ def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None): m.fail_json(msg=errmsg, rc=rc, stdout=stdout, stderr=stderr, cmd=cmd) else: return {}, rc, stdout, stderr - elif rc in [0, 106, 103]: + elif rc in [0, 102, 103, 106]: # zypper exit codes # 0: success # 106: signature verification failed + # 102: ZYPPER_EXIT_INF_REBOOT_NEEDED - Returned after a successful installation of a patch which requires reboot of computer. # 103: zypper was upgraded, run same command again if packages is None: firstrun = True @@ -587,12 +588,12 @@ def main(): elif state in ['installed', 'present', 'latest']: packages_changed, retvals = package_present(module, name, state == 'latest') - retvals['changed'] = retvals['rc'] == 0 and bool(packages_changed) + retvals['changed'] = retvals['rc'] in [0, 102] and bool(packages_changed) if module._diff: set_diff(module, retvals, packages_changed) - if retvals['rc'] != 0: + if retvals['rc'] not in [0, 102]: module.fail_json(msg="Zypper run failed.", **retvals) if not retvals['changed']: