Skip to content

Commit

Permalink
pkgng - add option use_globs (default=true) (ansible-collections#8633)
Browse files Browse the repository at this point in the history
* pkgng - add option use_globs (default=true) ansible-collections#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]>
  • Loading branch information
2 people authored and aioue committed Oct 1, 2024
1 parent 4183acb commit 8c86a60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
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, https://github.com/ansible-collections/community.general/pull/8633).
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.3.0
author: "bleader (@bleader)"
notes:
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
Expand Down Expand Up @@ -136,6 +143,12 @@
community.general.pkgng:
name: "*"
state: latest
- name: Upgrade foo/bar
community.general.pkgng:
name: foo/bar
state: latest
use_globs: false
'''


Expand All @@ -146,7 +159,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 @@ -156,7 +169,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 @@ -259,7 +272,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 @@ -289,7 +302,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 @@ -424,7 +437,9 @@ 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'),
),
supports_check_mode=True,
mutually_exclusive=[["rootdir", "chroot", "jail"]])

Expand Down Expand Up @@ -465,6 +480,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
- pkgng_upgrade_orig_noglobs is not changed

0 comments on commit 8c86a60

Please sign in to comment.