Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix proxy settings for elasticsearch_plugin.py #9774

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)."
29 changes: 16 additions & 13 deletions plugins/modules/elasticsearch_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,33 +163,38 @@ def parse_error(string):


def install_plugin(module, plugin_bin, plugin_name, version, src, url, proxy_host, proxy_port, timeout, force):
cmd_args = [plugin_bin, PACKAGE_STATE_MAP["present"]]
cmd = [plugin_bin, PACKAGE_STATE_MAP["present"]]
is_old_command = (os.path.basename(plugin_bin) == 'plugin')

# Timeout and version are only valid for plugin, not elasticsearch-plugin
if is_old_command:
if timeout:
cmd_args.append("--timeout %s" % timeout)
cmd.append("--timeout")
cmd.append(timeout)

if version:
plugin_name = plugin_name + '/' + version
cmd_args[2] = plugin_name
cmd[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)) # Older Elasticsearch versions

# Legacy ES 1.x
if url:
cmd_args.append("--url %s" % url)
cmd.append("--url")
cmd.append(url)

if force:
cmd_args.append("--batch")
cmd.append("--batch")
if src:
cmd_args.append(src)
cmd.append(src)
else:
cmd_args.append(plugin_name)

cmd = " ".join(cmd_args)
cmd.append(plugin_name)

if module.check_mode:
rc, out, err = 0, "check mode", ""
Expand All @@ -204,9 +209,7 @@ def install_plugin(module, plugin_bin, plugin_name, version, src, url, proxy_hos


def remove_plugin(module, plugin_bin, plugin_name):
cmd_args = [plugin_bin, PACKAGE_STATE_MAP["absent"], parse_plugin_repo(plugin_name)]

cmd = " ".join(cmd_args)
cmd = [plugin_bin, PACKAGE_STATE_MAP["absent"], parse_plugin_repo(plugin_name)]

if module.check_mode:
rc, out, err = 0, "check mode", ""
Expand Down