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

pkgng: fix error-handling when upgrading all (#5369)

* pkgng: fix error-handling when upgrading all

* provide for rc=1 in check_mode + test

* fix name of task in test

* add changelog fragment
This commit is contained in:
Alexei Znamensky 2022-10-23 22:42:53 +13:00 committed by GitHub
parent 389dfe9f09
commit baa8bd52ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 10 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- pkgng - fix case when ``pkg`` fails when trying to upgrade all packages (https://github.com/ansible-collections/community.general/issues/5363).

View file

@ -38,7 +38,7 @@ options:
state:
description:
- State of the package.
- 'Note: "latest" added in 2.7'
- 'Note: C(latest) added in 2.7.'
choices: [ 'present', 'latest', 'absent' ]
required: false
default: present
@ -149,10 +149,7 @@ def query_package(module, run_pkgng, name):
rc, out, err = run_pkgng('info', '-g', '-e', name)
if rc == 0:
return True
return False
return rc == 0
def query_update(module, run_pkgng, name):
@ -162,10 +159,7 @@ def query_update(module, run_pkgng, name):
# rc = 1, updates available
rc, out, err = run_pkgng('upgrade', '-g', '-n', name)
if rc == 1:
return True
return False
return rc == 1
def pkgng_older_than(module, pkgng_path, compare_version):
@ -191,7 +185,7 @@ def upgrade_packages(module, run_pkgng):
pkgng_args = ['upgrade']
pkgng_args.append('-n' if module.check_mode else '-y')
rc, out, err = run_pkgng(*pkgng_args)
rc, out, err = run_pkgng(*pkgng_args, check_rc=(not module.check_mode))
matches = re.findall('^Number of packages to be (?:upgraded|reinstalled): ([0-9]+)', out, re.MULTILINE)
for match in matches:

View file

@ -140,6 +140,42 @@
- pkgng_example4.changed
- not pkgng_example4_idempotent.changed
##
## pkgng - example - state=latest for out-of-date package without privileges
##
- name: Install intentionally out-of-date package and try to upgrade it with unprivileged user
block:
- ansible.builtin.user:
name: powerless
shell: /bin/bash
- name: Create out-of-date test package
import_tasks: create-outofdate-pkg.yml
- name: Install out-of-date test package
command: 'pkg add {{ pkgng_test_outofdate_pkg_path }}'
register: pkgng_example4_nopower_prepare
- name: Check for any available package upgrades with unprivileged user
become: true
become_user: powerless
pkgng:
name: '*'
state: latest
register: pkgng_example4_nopower_wildcard
ignore_errors: true
- name: Remove test out-of-date package
pkgng:
name: '{{ pkgng_test_pkg_name }}'
state: absent
- name: Ensure pkgng upgrades package correctly
assert:
that:
- not pkgng_example4_nopower_prepare.failed
- pkgng_example4_nopower_wildcard.failed
##
## pkgng - example - Install multiple packages in one command
##