From b5d57a35d6c310e98d9c4caaa09e3a899f7de304 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 26 Jan 2026 17:43:07 +0100 Subject: [PATCH] [PR #11442/72220a2b backport][stable-12] fix gem module compatibility with ruby-4-rubygems (#11452) fix gem module compatibility with ruby-4-rubygems (#11442) * fix gem module compatibility with ruby-4-rubygems rubygem's `query` command has recently been removed, see ruby/rubygems#9083. address this by using the `list` command instead. resolves #11397 * add changelog * Adjust changelog fragment. --------- (cherry picked from commit 72220a2b15ee3fa76511d8487c3683309509ca2f) Co-authored-by: glaszig Co-authored-by: Felix Fontein --- changelogs/fragments/11442-gem-module-ruby-4.yml | 2 ++ plugins/modules/gem.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/11442-gem-module-ruby-4.yml diff --git a/changelogs/fragments/11442-gem-module-ruby-4.yml b/changelogs/fragments/11442-gem-module-ruby-4.yml new file mode 100644 index 0000000000..9314cb8acd --- /dev/null +++ b/changelogs/fragments/11442-gem-module-ruby-4.yml @@ -0,0 +1,2 @@ +bugfixes: + - "gem - add compatibility with Ruby 4 rubygems (https://github.com/ansible-collections/community.general/issues/11397, https://github.com/ansible-collections/community.general/pull/11442)." diff --git a/plugins/modules/gem.py b/plugins/modules/gem.py index de0984e3ea..afacb282bf 100644 --- a/plugins/modules/gem.py +++ b/plugins/modules/gem.py @@ -160,13 +160,12 @@ def get_rubygems_environ(module): def get_installed_versions(module, remote=False): cmd = get_rubygems_path(module) - cmd.append("query") + cmd.append("list") cmd.extend(common_opts(module)) if remote: cmd.append("--remote") if module.params["repository"]: cmd.extend(["--source", module.params["repository"]]) - cmd.append("-n") cmd.append(f"^{module.params['name']}$") environ = get_rubygems_environ(module)