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:
parent
b2b4877532
commit
c0740ca398
2 changed files with 17 additions and 7 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
bugfixes:
|
||||||
|
- pacman - fix changed status when ignorepkg has been defined (https://github.com/ansible-collections/community.general/issues/1758).
|
|
@ -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:
|
||||||
|
if '[ignored]' not in p:
|
||||||
m = regex.search(p)
|
m = regex.search(p)
|
||||||
packages.append(m.group(1))
|
packages.append(m.group(1))
|
||||||
if module._diff:
|
if module._diff:
|
||||||
diff['before'] += "%s-%s\n" % (m.group(1), m.group(2))
|
diff['before'] += "%s-%s\n" % (m.group(1), m.group(2))
|
||||||
diff['after'] += "%s-%s\n" % (m.group(1), m.group(3))
|
diff['after'] += "%s-%s\n" % (m.group(1), m.group(3))
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
|
if packages:
|
||||||
module.exit_json(changed=True, msg="%s package(s) would be upgraded" % (len(data)), packages=packages, diff=diff)
|
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:
|
||||||
|
if packages:
|
||||||
module.exit_json(changed=True, msg='System upgraded', packages=packages, diff=diff)
|
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:
|
||||||
|
|
Loading…
Reference in a new issue