Skip to content

Commit

Permalink
elasticsearch_plugin: fix error when setting proxy settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Hovius committed Feb 18, 2025
1 parent a3fd357 commit b7e9c95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "elasticsearch_plugin - fix ``ERROR: D is not a recognized option`` issue when configuring proxy settings (https://github.com/ansible-collections/community.general/pull/9774, https://github.com/ansible-collections/community.general/issues/9773)."
16 changes: 11 additions & 5 deletions plugins/modules/elasticsearch_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later

from __future__ import absolute_import, division, print_function
__metaclass__ = type

__metaclass__ = type

DOCUMENTATION = r"""
module: elasticsearch_plugin
Expand Down Expand Up @@ -119,7 +119,6 @@

from ansible.module_utils.basic import AnsibleModule


PACKAGE_STATE_MAP = dict(
present="install",
absent="remove"
Expand Down Expand Up @@ -176,7 +175,12 @@ def install_plugin(module, plugin_bin, plugin_name, version, src, url, proxy_hos
cmd_args[2] = plugin_name

if proxy_host and proxy_port:
cmd_args.append("-DproxyHost=%s -DproxyPort=%s" % (proxy_host, proxy_port))
java_opts = ["-Dhttp.proxyHost=%s" % proxy_host,
"-Dhttp.proxyPort=%s" % proxy_port,
"-Dhttps.proxyHost=%s" % proxy_host,
"-Dhttps.proxyPort=%s" % proxy_port]
module.run_command_environ_update = dict(CLI_JAVA_OPTS=" ".join(java_opts), # Elasticsearch 8.x
ES_JAVA_OPTS=" ".join(java_opts)) # Elasticsearch below 8.x

# Legacy ES 1.x
if url:
Expand Down Expand Up @@ -246,7 +250,8 @@ def get_plugin_bin(module, plugin_bin=None):
break

if not valid_plugin_bin:
module.fail_json(msg='%s does not exist and no other valid plugin installers were found. Make sure Elasticsearch is installed.' % plugin_bin)
module.fail_json(
msg='%s does not exist and no other valid plugin installers were found. Make sure Elasticsearch is installed.' % plugin_bin)

return valid_plugin_bin

Expand Down Expand Up @@ -293,7 +298,8 @@ def main():
module.exit_json(changed=False, name=name, state=state)

if state == "present":
changed, cmd, out, err = install_plugin(module, plugin_bin, name, version, src, url, proxy_host, proxy_port, timeout, force)
changed, cmd, out, err = install_plugin(module, plugin_bin, name, version, src, url, proxy_host, proxy_port,
timeout, force)

elif state == "absent":
changed, cmd, out, err = remove_plugin(module, plugin_bin, name)
Expand Down

0 comments on commit b7e9c95

Please sign in to comment.