From 3312ae08af00c64d16e34d940d1c3991a3a11b92 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Sat, 3 Apr 2021 09:05:28 +1300 Subject: [PATCH] kibana_plugin: fixed remove call + run_command with list instead of str (#2143) * fixed remove call + run_command with list instead of str * fixed the other calls to run_command() * added changelog fragment * adjustment on run_command params * Update changelogs/fragments/2143-kibana_plugin-fixed-function-calls.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein --- ...143-kibana_plugin-fixed-function-calls.yml | 2 ++ .../modules/database/misc/kibana_plugin.py | 25 ++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) create mode 100644 changelogs/fragments/2143-kibana_plugin-fixed-function-calls.yml diff --git a/changelogs/fragments/2143-kibana_plugin-fixed-function-calls.yml b/changelogs/fragments/2143-kibana_plugin-fixed-function-calls.yml new file mode 100644 index 0000000000..54a41cd237 --- /dev/null +++ b/changelogs/fragments/2143-kibana_plugin-fixed-function-calls.yml @@ -0,0 +1,2 @@ +bugfixes: + - kibana_plugin - added missing parameters to ``remove_plugin`` when using ``state=present force=true``, and fix potential quoting errors when invoking ``kibana`` (https://github.com/ansible-collections/community.general/pull/2143). diff --git a/plugins/modules/database/misc/kibana_plugin.py b/plugins/modules/database/misc/kibana_plugin.py index e8daf2ff58..25d7719353 100644 --- a/plugins/modules/database/misc/kibana_plugin.py +++ b/plugins/modules/database/misc/kibana_plugin.py @@ -170,25 +170,23 @@ def install_plugin(module, plugin_bin, plugin_name, url, timeout, allow_root, ki cmd_args = [plugin_bin, "plugin", PACKAGE_STATE_MAP["present"], plugin_name] if url: - cmd_args.append("--url %s" % url) + cmd_args.extend(["--url", url]) if timeout: - cmd_args.append("--timeout %s" % timeout) + cmd_args.extend(["--timeout", timeout]) if allow_root: cmd_args.append('--allow-root') - cmd = " ".join(cmd_args) - if module.check_mode: - return True, cmd, "check mode", "" + return True, " ".join(cmd_args), "check mode", "" - rc, out, err = module.run_command(cmd) + rc, out, err = module.run_command(cmd_args) if rc != 0: reason = parse_error(out) module.fail_json(msg=reason) - return True, cmd, out, err + return True, " ".join(cmd_args), out, err def remove_plugin(module, plugin_bin, plugin_name, allow_root, kibana_version='4.6'): @@ -201,17 +199,15 @@ def remove_plugin(module, plugin_bin, plugin_name, allow_root, kibana_version='4 if allow_root: cmd_args.append('--allow-root') - cmd = " ".join(cmd_args) - if module.check_mode: - return True, cmd, "check mode", "" + return True, " ".join(cmd_args), "check mode", "" - rc, out, err = module.run_command(cmd) + rc, out, err = module.run_command(cmd_args) if rc != 0: reason = parse_error(out) module.fail_json(msg=reason) - return True, cmd, out, err + return True, " ".join(cmd_args), out, err def get_kibana_version(module, plugin_bin, allow_root): @@ -220,8 +216,7 @@ def get_kibana_version(module, plugin_bin, allow_root): if allow_root: cmd_args.append('--allow-root') - cmd = " ".join(cmd_args) - rc, out, err = module.run_command(cmd) + rc, out, err = module.run_command(cmd_args) if rc != 0: module.fail_json(msg="Failed to get Kibana version : %s" % err) @@ -269,7 +264,7 @@ def main(): if state == "present": if force: - remove_plugin(module, plugin_bin, name) + remove_plugin(module, plugin_bin, name, allow_root, kibana_version) changed, cmd, out, err = install_plugin(module, plugin_bin, name, url, timeout, allow_root, kibana_version) elif state == "absent":