Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkgng - add option use_globs (default=true) #8633

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8632-pkgng-add-option-use_globs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- pkgng - add option use_globs (default=true) to optionally disable glob patterns (https://github.com/ansible-collections/community.general/issues/8632).
vbotka marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 23 additions & 5 deletions plugins/modules/pkgng.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
type: bool
default: false
version_added: 1.3.0
use_globs:
description:
- Treat the package names as shell glob patterns.
required: false
type: bool
default: true
version_added: 9.2.0
vbotka marked this conversation as resolved.
Show resolved Hide resolved
author: "bleader (@bleader)"
notes:
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
Expand Down Expand Up @@ -137,6 +144,13 @@
community.general.pkgng:
name: "*"
state: latest

# "use_globs" support added in 9.2.0
vbotka marked this conversation as resolved.
Show resolved Hide resolved
- name: Upgrade foo/bar
community.general.pkgng:
name: foo/bar
state: latest
use_globs: false
'''


Expand All @@ -147,7 +161,7 @@

def query_package(module, run_pkgng, name):

rc, out, err = run_pkgng('info', '-g', '-e', name)
rc, out, err = run_pkgng('info', '-e', name)

return rc == 0

Expand All @@ -157,7 +171,7 @@ def query_update(module, run_pkgng, name):
# Check to see if a package upgrade is available.
# rc = 0, no updates available or package not installed
# rc = 1, updates available
rc, out, err = run_pkgng('upgrade', '-g', '-n', name)
rc, out, err = run_pkgng('upgrade', '-n', name)

return rc == 1

Expand Down Expand Up @@ -260,7 +274,7 @@ def install_packages(module, run_pkgng, packages, cached, state):
action_count[action] += len(package_list)
continue

pkgng_args = [action, '-g', '-U', '-y'] + package_list
pkgng_args = [action, '-U', '-y'] + package_list
rc, out, err = run_pkgng(*pkgng_args)
stdout += out
stderr += err
Expand Down Expand Up @@ -290,7 +304,7 @@ def install_packages(module, run_pkgng, packages, cached, state):


def annotation_query(module, run_pkgng, package, tag):
rc, out, err = run_pkgng('info', '-g', '-A', package)
rc, out, err = run_pkgng('info', '-A', package)
match = re.search(r'^\s*(?P<tag>%s)\s*:\s*(?P<value>\w+)' % tag, out, flags=re.MULTILINE)
if match:
return match.group('value')
Expand Down Expand Up @@ -425,7 +439,8 @@ def main():
rootdir=dict(required=False, type='path'),
chroot=dict(required=False, type='path'),
jail=dict(required=False, type='str'),
autoremove=dict(default=False, type='bool')),
autoremove=dict(default=False, type='bool'),
use_globs=dict(default=True, required=False, type='bool')),
vbotka marked this conversation as resolved.
Show resolved Hide resolved
supports_check_mode=True,
mutually_exclusive=[["rootdir", "chroot", "jail"]])

Expand Down Expand Up @@ -466,6 +481,9 @@ def main():
def run_pkgng(action, *args, **kwargs):
cmd = [pkgng_path, dir_arg, action]

if p["use_globs"] and action in ('info', 'install', 'upgrade',):
args = ('-g',) + args

pkgng_env = {'BATCH': 'yes'}

if p["ignore_osver"]:
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/targets/pkgng/tasks/install_single_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
get_mime: false
register: pkgng_install_stat_after

- name: Upgrade package (orig, no globs)
pkgng:
name: '{{ pkgng_test_pkg_category }}/{{ pkgng_test_pkg_name }}'
state: latest
use_globs: false
jail: '{{ pkgng_test_jail | default(omit) }}'
chroot: '{{ pkgng_test_chroot | default(omit) }}'
rootdir: '{{ pkgng_test_rootdir | default(omit) }}'
register: pkgng_upgrade_orig_noglobs

- name: Remove test package (if requested)
pkgng:
<<: *pkgng_install_params
Expand All @@ -56,3 +66,4 @@
- not pkgng_install_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
- pkgng_install_stat_after.stat.exists
- pkgng_install_stat_after.stat.executable
- not pkgng_upgrade_orig_noglobs.changed
vbotka marked this conversation as resolved.
Show resolved Hide resolved