From aeeb09f0da291ae1745f70158692b7f3da32eb9b Mon Sep 17 00:00:00 2001 From: Ge0rgi0s <34042518+Ge0rgi0s@users.noreply.github.com> Date: Mon, 16 May 2022 05:40:46 +0000 Subject: [PATCH] Set firstrun to avoid use before definition (#4667) * Set firstrun to avoid use before definition At the moment if zypper updates itself the parse_zypper_xml function calls itself with packages not None, but in check_mode zypper still needs to update itself -> rc = 103 and firstrun is undefined * Add changelog frament * Update changelogs/fragments/4651-zypper-checkmode-fix.yaml Co-authored-by: Felix Fontein Co-authored-by: Georg Vogt Co-authored-by: Felix Fontein --- changelogs/fragments/4651-zypper-checkmode-fix.yaml | 2 ++ plugins/modules/packaging/os/zypper.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/4651-zypper-checkmode-fix.yaml diff --git a/changelogs/fragments/4651-zypper-checkmode-fix.yaml b/changelogs/fragments/4651-zypper-checkmode-fix.yaml new file mode 100644 index 0000000000..403e4eead6 --- /dev/null +++ b/changelogs/fragments/4651-zypper-checkmode-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - zypper - fix undefined variable when running in check mode (https://github.com/ansible-collections/community.general/pull/4667). diff --git a/plugins/modules/packaging/os/zypper.py b/plugins/modules/packaging/os/zypper.py index ab49051b17..07d71169ec 100644 --- a/plugins/modules/packaging/os/zypper.py +++ b/plugins/modules/packaging/os/zypper.py @@ -323,6 +323,8 @@ def parse_zypper_xml(m, cmd, fail_not_found=True, packages=None): if packages is None: firstrun = True packages = {} + else: + firstrun = False solvable_list = dom.getElementsByTagName('solvable') for solvable in solvable_list: name = solvable.getAttribute('name')