From 44dfe9e1abda5e2ecc7050df0ce4d91d5d903764 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 26 Jan 2026 06:29:35 +0100 Subject: [PATCH] [PR #11440/53e1e86b backport][stable-12] Logstash plugin version fix (#11450) Logstash plugin version fix (#11440) * logstash_plugin: fix argument order when using version parameter * logstash_plugin: add integration tests * logstash_plugin: add changelog fragment (cherry picked from commit 53e1e86bcc2b8df25030dcbced1257e055f89f64) Co-authored-by: Nicolas Boutet --- ...tash-plugin-fix-version-argument-order.yml | 2 + plugins/modules/logstash_plugin.py | 4 +- .../targets/logstash_plugin/aliases | 5 ++ .../targets/logstash_plugin/tasks/main.yml | 72 +++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/11440-logstash-plugin-fix-version-argument-order.yml create mode 100644 tests/integration/targets/logstash_plugin/aliases create mode 100644 tests/integration/targets/logstash_plugin/tasks/main.yml diff --git a/changelogs/fragments/11440-logstash-plugin-fix-version-argument-order.yml b/changelogs/fragments/11440-logstash-plugin-fix-version-argument-order.yml new file mode 100644 index 0000000000..36e2f4c23f --- /dev/null +++ b/changelogs/fragments/11440-logstash-plugin-fix-version-argument-order.yml @@ -0,0 +1,2 @@ +bugfixes: + - logstash_plugin - fix argument order when using ``version`` parameter. The plugin name must come after options like ``--version`` for the ``logstash-plugin`` CLI to work correctly (https://github.com/ansible-collections/community.general/issues/10745, https://github.com/ansible-collections/community.general/pull/11440). diff --git a/plugins/modules/logstash_plugin.py b/plugins/modules/logstash_plugin.py index abaa275d28..a4aca01f21 100644 --- a/plugins/modules/logstash_plugin.py +++ b/plugins/modules/logstash_plugin.py @@ -94,7 +94,7 @@ def parse_error(string): def install_plugin(module, plugin_bin, plugin_name, version, proxy_host, proxy_port): - cmd_args = [plugin_bin, PACKAGE_STATE_MAP["present"], plugin_name] + cmd_args = [plugin_bin, PACKAGE_STATE_MAP["present"]] if version: cmd_args.extend(["--version", version]) @@ -102,6 +102,8 @@ def install_plugin(module, plugin_bin, plugin_name, version, proxy_host, proxy_p if proxy_host and proxy_port: cmd_args.extend([f"-DproxyHost={proxy_host}", f"-DproxyPort={proxy_port}"]) + cmd_args.append(plugin_name) + cmd = " ".join(cmd_args) if module.check_mode: diff --git a/tests/integration/targets/logstash_plugin/aliases b/tests/integration/targets/logstash_plugin/aliases new file mode 100644 index 0000000000..bd1f024441 --- /dev/null +++ b/tests/integration/targets/logstash_plugin/aliases @@ -0,0 +1,5 @@ +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +unsupported diff --git a/tests/integration/targets/logstash_plugin/tasks/main.yml b/tests/integration/targets/logstash_plugin/tasks/main.yml new file mode 100644 index 0000000000..90b2dc1d76 --- /dev/null +++ b/tests/integration/targets/logstash_plugin/tasks/main.yml @@ -0,0 +1,72 @@ +--- +#################################################################### +# WARNING: These are designed specifically for Ansible tests # +# and should not be used as examples of how to write Ansible roles # +#################################################################### + +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +- name: Check if logstash-plugin is available + ansible.builtin.stat: + path: /usr/share/logstash/bin/logstash-plugin + register: logstash_plugin_bin + +- name: Run logstash_plugin tests + when: logstash_plugin_bin.stat.exists + block: + - name: Install plugin without version (should succeed) + community.general.logstash_plugin: + name: logstash-filter-dissect + state: present + register: install_no_version + + - name: Assert plugin installed + ansible.builtin.assert: + that: + - install_no_version is changed + + - name: Install same plugin again (idempotency) + community.general.logstash_plugin: + name: logstash-filter-dissect + state: present + register: install_no_version_again + + - name: Assert idempotency without version + ansible.builtin.assert: + that: + - install_no_version_again is not changed + + - name: Remove plugin for version test + community.general.logstash_plugin: + name: logstash-filter-dissect + state: absent + + - name: Install plugin with specific version + community.general.logstash_plugin: + name: logstash-filter-dissect + state: present + version: "3.2.0" + register: install_with_version + + - name: Assert plugin with version installed + ansible.builtin.assert: + that: + - install_with_version is changed + + - name: Verify command has correct argument order + ansible.builtin.assert: + that: + # The cmd output should show --version before plugin name + - "'--version' in install_with_version.cmd" + - "'3.2.0' in install_with_version.cmd" + - "install_with_version.cmd.index('--version') < install_with_version.cmd.index('logstash-filter-dissect')" + + always: + - name: Cleanup - remove test plugin + community.general.logstash_plugin: + name: logstash-filter-dissect + state: absent + when: logstash_plugin_bin.stat.exists + ignore_errors: true