mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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 <felix@fontein.de> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update tests/integration/targets/pkgng/tasks/install_single_package.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/pkgng.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
e1148e6bdc
commit
e3fb817a21
3 changed files with 36 additions and 5 deletions
2
changelogs/fragments/8632-pkgng-add-option-use_globs.yml
Normal file
2
changelogs/fragments/8632-pkgng-add-option-use_globs.yml
Normal file
|
@ -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).
|
|
@ -100,6 +100,13 @@ options:
|
||||||
type: bool
|
type: bool
|
||||||
default: false
|
default: false
|
||||||
version_added: 1.3.0
|
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)"
|
author: "bleader (@bleader)"
|
||||||
notes:
|
notes:
|
||||||
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
|
- When using pkgsite, be careful that already in cache packages won't be downloaded again.
|
||||||
|
@ -136,6 +143,12 @@ EXAMPLES = '''
|
||||||
community.general.pkgng:
|
community.general.pkgng:
|
||||||
name: "*"
|
name: "*"
|
||||||
state: latest
|
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):
|
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
|
return rc == 0
|
||||||
|
|
||||||
|
@ -156,7 +169,7 @@ def query_update(module, run_pkgng, name):
|
||||||
# Check to see if a package upgrade is available.
|
# Check to see if a package upgrade is available.
|
||||||
# rc = 0, no updates available or package not installed
|
# rc = 0, no updates available or package not installed
|
||||||
# rc = 1, updates available
|
# rc = 1, updates available
|
||||||
rc, out, err = run_pkgng('upgrade', '-g', '-n', name)
|
rc, out, err = run_pkgng('upgrade', '-n', name)
|
||||||
|
|
||||||
return rc == 1
|
return rc == 1
|
||||||
|
|
||||||
|
@ -259,7 +272,7 @@ def install_packages(module, run_pkgng, packages, cached, state):
|
||||||
action_count[action] += len(package_list)
|
action_count[action] += len(package_list)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pkgng_args = [action, '-g', '-U', '-y'] + package_list
|
pkgng_args = [action, '-U', '-y'] + package_list
|
||||||
rc, out, err = run_pkgng(*pkgng_args)
|
rc, out, err = run_pkgng(*pkgng_args)
|
||||||
stdout += out
|
stdout += out
|
||||||
stderr += err
|
stderr += err
|
||||||
|
@ -289,7 +302,7 @@ def install_packages(module, run_pkgng, packages, cached, state):
|
||||||
|
|
||||||
|
|
||||||
def annotation_query(module, run_pkgng, package, tag):
|
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)
|
match = re.search(r'^\s*(?P<tag>%s)\s*:\s*(?P<value>\w+)' % tag, out, flags=re.MULTILINE)
|
||||||
if match:
|
if match:
|
||||||
return match.group('value')
|
return match.group('value')
|
||||||
|
@ -424,7 +437,9 @@ def main():
|
||||||
rootdir=dict(required=False, type='path'),
|
rootdir=dict(required=False, type='path'),
|
||||||
chroot=dict(required=False, type='path'),
|
chroot=dict(required=False, type='path'),
|
||||||
jail=dict(required=False, type='str'),
|
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,
|
supports_check_mode=True,
|
||||||
mutually_exclusive=[["rootdir", "chroot", "jail"]])
|
mutually_exclusive=[["rootdir", "chroot", "jail"]])
|
||||||
|
|
||||||
|
@ -465,6 +480,9 @@ def main():
|
||||||
def run_pkgng(action, *args, **kwargs):
|
def run_pkgng(action, *args, **kwargs):
|
||||||
cmd = [pkgng_path, dir_arg, action]
|
cmd = [pkgng_path, dir_arg, action]
|
||||||
|
|
||||||
|
if p["use_globs"] and action in ('info', 'install', 'upgrade',):
|
||||||
|
args = ('-g',) + args
|
||||||
|
|
||||||
pkgng_env = {'BATCH': 'yes'}
|
pkgng_env = {'BATCH': 'yes'}
|
||||||
|
|
||||||
if p["ignore_osver"]:
|
if p["ignore_osver"]:
|
||||||
|
|
|
@ -40,6 +40,16 @@
|
||||||
get_mime: false
|
get_mime: false
|
||||||
register: pkgng_install_stat_after
|
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)
|
- name: Remove test package (if requested)
|
||||||
pkgng:
|
pkgng:
|
||||||
<<: *pkgng_install_params
|
<<: *pkgng_install_params
|
||||||
|
@ -56,3 +66,4 @@
|
||||||
- not pkgng_install_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
|
- not pkgng_install_idempotent_cached.stdout is match("Updating \w+ repository catalogue\.\.\.")
|
||||||
- pkgng_install_stat_after.stat.exists
|
- pkgng_install_stat_after.stat.exists
|
||||||
- pkgng_install_stat_after.stat.executable
|
- pkgng_install_stat_after.stat.executable
|
||||||
|
- pkgng_upgrade_orig_noglobs is not changed
|
||||||
|
|
Loading…
Reference in a new issue