diff --git a/changelogs/fragments/8632-pkgng-add-option-use_globs.yml b/changelogs/fragments/8632-pkgng-add-option-use_globs.yml new file mode 100644 index 0000000000..d3e03959d5 --- /dev/null +++ b/changelogs/fragments/8632-pkgng-add-option-use_globs.yml @@ -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). diff --git a/plugins/modules/pkgng.py b/plugins/modules/pkgng.py index e283311c8e..7a04ee3a6e 100644 --- a/plugins/modules/pkgng.py +++ b/plugins/modules/pkgng.py @@ -100,6 +100,13 @@ options: 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. @@ -136,6 +143,12 @@ EXAMPLES = ''' community.general.pkgng: name: "*" state: latest + +- name: Upgrade foo/bar + community.general.pkgng: + name: foo/bar + state: latest + use_globs: false ''' @@ -146,7 +159,7 @@ from ansible.module_utils.basic import AnsibleModule 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 @@ -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 @@ -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 @@ -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%s)\s*:\s*(?P\w+)' % tag, out, flags=re.MULTILINE) if match: return match.group('value') @@ -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"]]) @@ -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"]: diff --git a/tests/integration/targets/pkgng/tasks/install_single_package.yml b/tests/integration/targets/pkgng/tasks/install_single_package.yml index 5ba529af35..7f0886af8b 100644 --- a/tests/integration/targets/pkgng/tasks/install_single_package.yml +++ b/tests/integration/targets/pkgng/tasks/install_single_package.yml @@ -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 @@ -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