1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-03 18:56:55 +00:00

pkgng: fix #3428; install from local file

Fixes a bug in which the module reported failure
when installing from a local (to the target host)
file path.

Fixes #3428
This commit is contained in:
Ross Williams 2021-10-13 19:20:45 +00:00
parent 75212ad73d
commit 5f94eac41f
3 changed files with 45 additions and 2 deletions

View file

@ -140,6 +140,7 @@ EXAMPLES = '''
from collections import defaultdict
import os.path
import re
from ansible.module_utils.basic import AnsibleModule
@ -154,6 +155,23 @@ def query_package(module, run_pkgng, name):
return False
def query_package_name(module, run_pkgng, package):
# Borrowing this pkg filename detection logic from
# https://github.com/freebsd/pkg/blob/06b59b5/libpkg/pkg_jobs.c#L193-L237
filename_match = re.search(r'\.(pkg|tzst|t[xbg]z|tar)', package, re.IGNORECASE)
if filename_match is not None and os.path.exists(package):
rc, out, err = run_pkgng('query', '-F', package, '%n')
if rc != 0:
module.fail_json(msg="failed to get name from package file %s: %s" % (package, out), stderr=err)
package_name = out.strip()
else:
package_name = package
return package_name
def query_update(module, run_pkgng, name):
# Check to see if a package upgrade is available.
@ -273,10 +291,12 @@ def install_packages(module, run_pkgng, packages, cached, state):
# individually verify packages are in requested state
for package in package_list:
verified = False
package_name = query_package_name(module, run_pkgng, package)
if action == 'install':
verified = query_package(module, run_pkgng, package)
verified = query_package(module, run_pkgng, package_name)
elif action == 'upgrade':
verified = not query_update(module, run_pkgng, package)
verified = not query_update(module, run_pkgng, package_name)
if verified:
action_count[action] += 1