diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2022-09-28 10:13:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-28 09:13:00 -0500 |
commit | 6b8432850f1cac69c3d8588be1514cbff3b1f392 (patch) | |
tree | 31ca1d0053e32030a6c5aaa728bb3ca2105b37d5 | |
parent | 0747c5c859afee760eebd2457290f491d2f16bbc (diff) | |
download | ansible-6b8432850f1cac69c3d8588be1514cbff3b1f392.tar.gz |
apt module, prevent tb from invalid type for pkg (#78666) (#78907)
* apt module, prevent tb from invalid type for pkg
see #78663
(cherry picked from commit 7acd4f75c037974be7fa4e7eabe55152dfc57500)
-rw-r--r-- | changelogs/fragments/apt_notb.yml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/apt.py | 10 |
2 files changed, 9 insertions, 3 deletions
diff --git a/changelogs/fragments/apt_notb.yml b/changelogs/fragments/apt_notb.yml new file mode 100644 index 0000000000..30d7c41da0 --- /dev/null +++ b/changelogs/fragments/apt_notb.yml @@ -0,0 +1,2 @@ +bugfixes: + - apt module should not traceback on invalid type given as package. issue 78663. diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index ac1a0f65b6..1070c30089 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -365,8 +365,8 @@ import time from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.locale import get_best_parsable_locale from ansible.module_utils.common.respawn import has_respawned, probe_interpreters_for_module, respawn_module -from ansible.module_utils._text import to_native -from ansible.module_utils.six import PY3 +from ansible.module_utils._text import to_native, to_text +from ansible.module_utils.six import PY3, string_types from ansible.module_utils.urls import fetch_file DPKG_OPTIONS = 'force-confdef,force-confold' @@ -617,6 +617,10 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache): new_pkgspec = [] if pkgspec: for pkgspec_pattern in pkgspec: + + if not isinstance(pkgspec_pattern, string_types): + m.fail_json(msg="Invalid type for package name, expected string but got %s" % type(pkgspec_pattern)) + pkgname_pattern, version_cmp, version = package_split(pkgspec_pattern) # note that none of these chars is allowed in a (debian) pkgname @@ -639,7 +643,7 @@ def expand_pkgspec_from_fnmatches(m, pkgspec, cache): matches = fnmatch.filter(pkg_name_cache, pkgname_pattern) if not matches: - m.fail_json(msg="No package(s) matching '%s' available" % str(pkgname_pattern)) + m.fail_json(msg="No package(s) matching '%s' available" % to_text(pkgname_pattern)) else: new_pkgspec.extend(matches) else: |