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) (#2945)

* 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:37 +02:00 committed by GitHub
parent eec4861c36
commit 2ce9ea8c54
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

@ -254,16 +254,23 @@ def upgrade(module, pacman_path):
# e.g., "ansible 2.7.1-1 -> 2.7.2-1" # e.g., "ansible 2.7.1-1 -> 2.7.2-1"
regex = re.compile(r'([\w+\-.@]+) (\S+-\S+) -> (\S+-\S+)') regex = re.compile(r'([\w+\-.@]+) (\S+-\S+) -> (\S+-\S+)')
for p in data: for p in data:
m = regex.search(p) if '[ignored]' not in p:
packages.append(m.group(1)) m = regex.search(p)
if module._diff: packages.append(m.group(1))
diff['before'] += "%s-%s\n" % (m.group(1), m.group(2)) if module._diff:
diff['after'] += "%s-%s\n" % (m.group(1), m.group(3)) 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: 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) rc, stdout, stderr = module.run_command(cmdupgrade, check_rc=False)
if rc == 0: 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: else:
module.fail_json(msg="Could not upgrade") module.fail_json(msg="Could not upgrade")
else: else: