From 881f64c93b617f3a9f7c4a41eb6aaa987f3706c5 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sat, 2 May 2026 10:45:27 +1200 Subject: [PATCH] logstash_plugin: fix proxy support and improve error reporting (#11951) * fix(logstash_plugin): use env vars for proxy, expose stderr on failure Replace broken -DproxyHost/-DproxyPort JVM flags with http_proxy/https_proxy environment variables, which are respected by modern Logstash bundled JDK. Also include stderr in fail_json so the actual error output is visible. Fixes #8650 * feat(changelog): add fragment for PR 11951 --- .../11951-logstash-plugin-proxy-env-vars.yml | 2 ++ plugins/modules/logstash_plugin.py | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/11951-logstash-plugin-proxy-env-vars.yml diff --git a/changelogs/fragments/11951-logstash-plugin-proxy-env-vars.yml b/changelogs/fragments/11951-logstash-plugin-proxy-env-vars.yml new file mode 100644 index 0000000000..56e9e409de --- /dev/null +++ b/changelogs/fragments/11951-logstash-plugin-proxy-env-vars.yml @@ -0,0 +1,2 @@ +bugfixes: + - "logstash_plugin - use ``http_proxy``/``https_proxy`` environment variables for proxy support instead of broken JVM flags; expose ``stderr`` on failure (https://github.com/ansible-collections/community.general/issues/8650, https://github.com/ansible-collections/community.general/pull/11951)." diff --git a/plugins/modules/logstash_plugin.py b/plugins/modules/logstash_plugin.py index 13978bf23f..a0cae55aef 100644 --- a/plugins/modules/logstash_plugin.py +++ b/plugins/modules/logstash_plugin.py @@ -39,6 +39,10 @@ options: type: str description: - Proxy host to use during plugin installation. + - Can be specified as a hostname (for example, V(myproxy.example.com)) or as a URL (for example, V(http://myproxy.example.com)). + When specified without a scheme, V(http://) is assumed. + - Sets the O(proxy_host):O(proxy_port) combination as the E(http_proxy) and E(https_proxy) environment variables + when running the C(logstash-plugin) command. proxy_port: type: str description: @@ -99,21 +103,24 @@ def install_plugin(module, plugin_bin, plugin_name, version, proxy_host, proxy_p if version: cmd_args.extend(["--version", version]) - if proxy_host and proxy_port: - cmd_args.extend([f"-DproxyHost={proxy_host}", f"-DproxyPort={proxy_port}"]) - cmd_args.append(plugin_name) + environ_update = {} + if proxy_host and proxy_port: + scheme = proxy_host if "://" in proxy_host else f"http://{proxy_host}" + proxy_url = f"{scheme}:{proxy_port}" + environ_update = {"http_proxy": proxy_url, "https_proxy": proxy_url} + cmd = " ".join(cmd_args) if module.check_mode: rc, out, err = 0, "check mode", "" else: - rc, out, err = module.run_command(cmd_args) + rc, out, err = module.run_command(cmd_args, environ_update=environ_update) if rc != 0: reason = parse_error(out) - module.fail_json(msg=reason) + module.fail_json(msg=reason, stderr=err) return True, cmd, out, err @@ -130,7 +137,7 @@ def remove_plugin(module, plugin_bin, plugin_name): if rc != 0: reason = parse_error(out) - module.fail_json(msg=reason) + module.fail_json(msg=reason, stderr=err) return True, cmd, out, err