1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

pkgng: handle space- and comma-separated lists

The module expects a list of strings in the `name` parameter,
but long-standing documentation showed space- and comma-delimited
lists as a valid way of telling the module to act on multiple
packages. Passing these lists through to the `pkg` command can
have unexpected side-effects of upgrading packages when
`state=present` rather than `state=latest` and could result
in the module reporting the wrong number of packages for each
action performed.
This commit is contained in:
Ross Williams 2021-10-11 19:19:06 +00:00
parent 73eafc126f
commit 3e0eb392d1
2 changed files with 13 additions and 2 deletions

View file

@ -1,3 +1,4 @@
bugfixes:
- 'pkgng - `name=* state=latest` check for upgrades did not count "Number of packages to be reinstalled" as a `changed` action, giving incorrect results in both regular and check mode'
- 'pkgng - PR #3393 (https://github.com/ansible-collections/community.general/pull/3393) broke `check_mode` so that the module always reports `not changed`; fix regression so module reports number of upgrade or install actions that would be performed'
- 'pkgng - The module will now convert a single space- or comma-separated name parameter to a list. The documentation had given wrong examples in which multiple space- or comma-separated packages were specified in the `name` parameter, rather than using correct YAML list syntax. `pkgng` module documentation has also been updated'

View file

@ -113,12 +113,16 @@ EXAMPLES = '''
- name: Annotate package foo and bar
community.general.pkgng:
name: foo,bar
name:
- foo
- bar
annotation: '+test1=baz,-test2,:test3=foobar'
- name: Remove packages foo and bar
community.general.pkgng:
name: foo,bar
name:
- foo
- bar
state: absent
# "latest" support added in 2.7
@ -476,6 +480,12 @@ def main():
msgs.append(_msg)
# Operate on named packages
if len(pkgs) == 1:
# The documentation used to show multiple packages specified in one line
# with comma or space delimiters. That doesn't result in a YAML list, and
# wrong actions (install vs upgrade) can be reported if those
# comma- or space-delimited strings make it to the pkg command line.
pkgs = re.split(r'[,\s]', pkgs[0])
named_packages = [pkg for pkg in pkgs if pkg != '*']
if p["state"] in ("present", "latest") and named_packages:
_changed, _msg, _out, _err = install_packages(module, pkgng_path, named_packages,