1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pacman: fix changed status when ignorepkg has been defined (#2936) (#2944)

* pacman: fix returned code when ignorepkg has been defined

* add changelog

* make ignored check preciser

(cherry picked from commit c0740ca398)

Co-authored-by: Amin Vakil <info@aminvakil.com>
This commit is contained in:
patchback[bot] 2021-07-07 06:53:34 +02:00 committed by GitHub
parent ea873ae471
commit ce92da7e70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- pacman - fix changed status when ignorepkg has been defined (https://github.com/ansible-collections/community.general/issues/1758).

View file

@ -237,16 +237,23 @@ def upgrade(module, pacman_path):
# e.g., "ansible 2.7.1-1 -> 2.7.2-1"
regex = re.compile(r'([\w+\-.@]+) (\S+-\S+) -> (\S+-\S+)')
for p in data:
m = regex.search(p)
packages.append(m.group(1))
if module._diff:
diff['before'] += "%s-%s\n" % (m.group(1), m.group(2))
diff['after'] += "%s-%s\n" % (m.group(1), m.group(3))
if '[ignored]' not in p:
m = regex.search(p)
packages.append(m.group(1))
if module._diff:
diff['before'] += "%s-%s\n" % (m.group(1), m.group(2))
diff['after'] += "%s-%s\n" % (m.group(1), m.group(3))
if module.check_mode:
module.exit_json(changed=True, msg="%s package(s) would be upgraded" % (len(data)), packages=packages, diff=diff)
if packages:
module.exit_json(changed=True, msg="%s package(s) would be upgraded" % (len(data)), packages=packages, diff=diff)
else:
module.exit_json(changed=False, msg='Nothing to upgrade', packages=packages)
rc, stdout, stderr = module.run_command(cmdupgrade, check_rc=False)
if rc == 0:
module.exit_json(changed=True, msg='System upgraded', packages=packages, diff=diff)
if packages:
module.exit_json(changed=True, msg='System upgraded', packages=packages, diff=diff)
else:
module.exit_json(changed=False, msg='Nothing to upgrade', packages=packages)
else:
module.fail_json(msg="Could not upgrade")
else: