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)

* pacman: fix returned code when ignorepkg has been defined

* add changelog

* make ignored check preciser
This commit is contained in:
Amin Vakil 2021-07-07 00:36:36 +04:30 committed by GitHub
parent b2b4877532
commit c0740ca398
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"
regex = re.compile(r'([\w+\-.@]+) (\S+-\S+) -> (\S+-\S+)')
for p in data:
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:
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:
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: