Skip to content

Commit e3fb817

Browse files
vbotkafelixfontein
andauthored
pkgng - add option use_globs (default=true) (#8633)
* pkgng - add option use_globs (default=true) #8632 * Fix lint. * Update changelogs/fragments/8632-pkgng-add-option-use_globs.yml Co-authored-by: Felix Fontein <[email protected]> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <[email protected]> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <[email protected]> * Update tests/integration/targets/pkgng/tasks/install_single_package.yml Co-authored-by: Felix Fontein <[email protected]> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]>
1 parent e1148e6 commit e3fb817

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- pkgng - add option ``use_globs`` (default ``true``) to optionally disable glob patterns (https://github.com/ansible-collections/community.general/issues/8632, https://github.com/ansible-collections/community.general/pull/8633).

plugins/modules/pkgng.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@
100100
type: bool
101101
default: false
102102
version_added: 1.3.0
103+
use_globs:
104+
description:
105+
- Treat the package names as shell glob patterns.
106+
required: false
107+
type: bool
108+
default: true
109+
version_added: 9.3.0
103110
author: "bleader (@bleader)"
104111
notes:
105112
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
@@ -136,6 +143,12 @@
136143
community.general.pkgng:
137144
name: "*"
138145
state: latest
146+
147+
- name: Upgrade foo/bar
148+
community.general.pkgng:
149+
name: foo/bar
150+
state: latest
151+
use_globs: false
139152
'''
140153

141154

@@ -146,7 +159,7 @@
146159

147160
def query_package(module, run_pkgng, name):
148161

149-
rc, out, err = run_pkgng('info', '-g', '-e', name)
162+
rc, out, err = run_pkgng('info', '-e', name)
150163

151164
return rc == 0
152165

@@ -156,7 +169,7 @@ def query_update(module, run_pkgng, name):
156169
# Check to see if a package upgrade is available.
157170
# rc = 0, no updates available or package not installed
158171
# rc = 1, updates available
159-
rc, out, err = run_pkgng('upgrade', '-g', '-n', name)
172+
rc, out, err = run_pkgng('upgrade', '-n', name)
160173

161174
return rc == 1
162175

@@ -259,7 +272,7 @@ def install_packages(module, run_pkgng, packages, cached, state):
259272
action_count[action] += len(package_list)
260273
continue
261274

262-
pkgng_args = [action, '-g', '-U', '-y'] + package_list
275+
pkgng_args = [action, '-U', '-y'] + package_list
263276
rc, out, err = run_pkgng(*pkgng_args)
264277
stdout += out
265278
stderr += err
@@ -289,7 +302,7 @@ def install_packages(module, run_pkgng, packages, cached, state):
289302

290303

291304
def annotation_query(module, run_pkgng, package, tag):
292-
rc, out, err = run_pkgng('info', '-g', '-A', package)
305+
rc, out, err = run_pkgng('info', '-A', package)
293306
match = re.search(r'^\s*(?P<tag>%s)\s*:\s*(?P<value>\w+)' % tag, out, flags=re.MULTILINE)
294307
if match:
295308
return match.group('value')
@@ -424,7 +437,9 @@ def main():
424437
rootdir=dict(required=False, type='path'),
425438
chroot=dict(required=False, type='path'),
426439
jail=dict(required=False, type='str'),
427-
autoremove=dict(default=False, type='bool')),
440+
autoremove=dict(default=False, type='bool'),
441+
use_globs=dict(default=True, required=False, type='bool'),
442+
),
428443
supports_check_mode=True,
429444
mutually_exclusive=[["rootdir", "chroot", "jail"]])
430445

@@ -465,6 +480,9 @@ def main():
465480
def run_pkgng(action, *args, **kwargs):
466481
cmd = [pkgng_path, dir_arg, action]
467482

483+
if p["use_globs"] and action in ('info', 'install', 'upgrade',):
484+
args = ('-g',) + args
485+
468486
pkgng_env = {'BATCH': 'yes'}
469487

470488
if p["ignore_osver"]:

tests/integration/targets/pkgng/tasks/install_single_package.yml

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
get_mime: false
4141
register: pkgng_install_stat_after
4242

43+
- name: Upgrade package (orig, no globs)
44+
pkgng:
45+
name: '{{ pkgng_test_pkg_category }}/{{ pkgng_test_pkg_name }}'
46+
state: latest
47+
use_globs: false
48+
jail: '{{ pkgng_test_jail | default(omit) }}'
49+
chroot: '{{ pkgng_test_chroot | default(omit) }}'
50+
rootdir: '{{ pkgng_test_rootdir | default(omit) }}'
51+
register: pkgng_upgrade_orig_noglobs
52+
4353
- name: Remove test package (if requested)
4454
pkgng:
4555
<<: *pkgng_install_params
@@ -56,3 +66,4 @@
5666
- not pkgng_install_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
5767
- pkgng_install_stat_after.stat.exists
5868
- pkgng_install_stat_after.stat.executable
69+
- pkgng_upgrade_orig_noglobs is not changed

0 commit comments

Comments
 (0)