diff --git a/changelogs/fragments/3526-pkgng-add-integration-tests.yml b/changelogs/fragments/3526-pkgng-add-integration-tests.yml new file mode 100644 index 0000000000..150b9435df --- /dev/null +++ b/changelogs/fragments/3526-pkgng-add-integration-tests.yml @@ -0,0 +1,2 @@ +bugfixes: + - 'pkgng - `name=* state=latest` check for upgrades did not count "Number of packages to be reinstalled" as a `changed` action, giving incorrect results in both regular and check mode' diff --git a/plugins/modules/packaging/os/pkgng.py b/plugins/modules/packaging/os/pkgng.py index 4b033dd738..5d45820521 100644 --- a/plugins/modules/packaging/os/pkgng.py +++ b/plugins/modules/packaging/os/pkgng.py @@ -191,9 +191,10 @@ def upgrade_packages(module, pkgng_path, dir_arg): cmd += " -n" rc, out, err = module.run_command(cmd) - match = re.search('^Number of packages to be upgraded: ([0-9]+)', out, re.MULTILINE) - if match: - upgraded_c = int(match.group(1)) + for action in ('upgraded', 'reinstalled',): + match = re.search('^Number of packages to be %s: ([0-9]+)' % (action,), out, re.MULTILINE) + if match: + upgraded_c += int(match.group(1)) if upgraded_c > 0: return (True, "updated %s package(s)" % upgraded_c, out, err)