1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

kibana_plugin: Use update plugin command syntax (#46593)

From 4.6 version onwards, Kibana plugins are installed or removed using
'kibana-plugin' command. This fix updates module with respective syntax.

Fixes: #27722

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2018-11-15 10:01:21 +05:30 committed by ansibot
parent 7b91d298d0
commit 63bb4c5706

View file

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# (c) 2016, Thierno IB. BARRY @barryib # Copyright (c) 2016, Thierno IB. BARRY @barryib
# Sponsored by Polyconseil http://polyconseil.fr. # Sponsored by Polyconseil http://polyconseil.fr.
# #
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
@ -10,9 +10,11 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {
'status': ['preview'], 'metadata_version': '1.1',
'supported_by': 'community'} 'status': ['preview'],
'supported_by': 'community'
}
DOCUMENTATION = ''' DOCUMENTATION = '''
@ -20,44 +22,44 @@ DOCUMENTATION = '''
module: kibana_plugin module: kibana_plugin
short_description: Manage Kibana plugins short_description: Manage Kibana plugins
description: description:
- Manages Kibana plugins. - This module can be used to manage Kibana plugins.
version_added: "2.2" version_added: "2.2"
author: Thierno IB. BARRY (@barryib) author: Thierno IB. BARRY (@barryib)
options: options:
name: name:
description: description:
- Name of the plugin to install - Name of the plugin to install.
required: True required: True
state: state:
description: description:
- Desired state of a plugin. - Desired state of a plugin.
choices: ["present", "absent"] choices: ["present", "absent"]
default: present default: present
url: url:
description: description:
- Set exact URL to download the plugin from. - Set exact URL to download the plugin from.
For local file, prefix its absolute path with file:// - For local file, prefix its absolute path with file://
timeout: timeout:
description: description:
- "Timeout setting: 30s, 1m, 1h..." - "Timeout setting: 30s, 1m, 1h etc."
default: 1m default: 1m
plugin_bin: plugin_bin:
description: description:
- Location of the plugin binary - Location of the Kibana binary.
default: /opt/kibana/bin/kibana default: /opt/kibana/bin/kibana
plugin_dir: plugin_dir:
description: description:
- Your configured plugin directory specified in Kibana - Your configured plugin directory specified in Kibana.
default: /opt/kibana/installedPlugins/ default: /opt/kibana/installedPlugins/
version: version:
description: description:
- Version of the plugin to be installed. - Version of the plugin to be installed.
If plugin exists with previous version, it will NOT be updated if C(force) is not set to yes - If plugin exists with previous version, plugin will NOT be updated unless C(force) is set to yes.
force: force:
description: description:
- Delete and re-install the plugin. Can be useful for plugins update - Delete and re-install the plugin. Can be useful for plugins update.
type: bool type: bool
default: 'no' default: 'no'
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -80,7 +82,7 @@ EXAMPLES = '''
RETURN = ''' RETURN = '''
cmd: cmd:
description: the launched command during plugin mangement (install / remove) description: the launched command during plugin management (install / remove)
returned: success returned: success
type: string type: string
name: name:
@ -110,7 +112,7 @@ state:
''' '''
import os import os
from distutils.version import LooseVersion
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -151,11 +153,19 @@ def parse_error(string):
return string return string
def install_plugin(module, plugin_bin, plugin_name, url, timeout): def install_plugin(module, plugin_bin, plugin_name, url, timeout, kibana_version='4.6'):
cmd_args = [plugin_bin, "plugin", PACKAGE_STATE_MAP["present"], plugin_name] if LooseVersion(kibana_version) > LooseVersion('4.6'):
kibana_plugin_bin = os.path.join(os.path.dirname(plugin_bin), 'kibana-plugin')
cmd_args = [kibana_plugin_bin, "install"]
if url:
cmd_args.append(url)
else:
cmd_args.append(plugin_name)
else:
cmd_args = [plugin_bin, "plugin", PACKAGE_STATE_MAP["present"], plugin_name]
if url: if url:
cmd_args.append("--url %s" % url) cmd_args.append("--url %s" % url)
if timeout: if timeout:
cmd_args.append("--timeout %s" % timeout) cmd_args.append("--timeout %s" % timeout)
@ -173,8 +183,12 @@ def install_plugin(module, plugin_bin, plugin_name, url, timeout):
return True, cmd, out, err return True, cmd, out, err
def remove_plugin(module, plugin_bin, plugin_name): def remove_plugin(module, plugin_bin, plugin_name, kibana_version='4.6'):
cmd_args = [plugin_bin, "plugin", PACKAGE_STATE_MAP["absent"], plugin_name] if LooseVersion(kibana_version) > LooseVersion('4.6'):
kibana_plugin_bin = os.path.join(os.path.dirname(plugin_bin), 'kibana-plugin')
cmd_args = [kibana_plugin_bin, "remove", plugin_name]
else:
cmd_args = [plugin_bin, "plugin", PACKAGE_STATE_MAP["absent"], plugin_name]
cmd = " ".join(cmd_args) cmd = " ".join(cmd_args)
@ -189,6 +203,16 @@ def remove_plugin(module, plugin_bin, plugin_name):
return True, cmd, out, err return True, cmd, out, err
def get_kibana_version(module, plugin_bin):
cmd_args = [plugin_bin, '--version']
cmd = " ".join(cmd_args)
rc, out, err = module.run_command(cmd)
if rc != 0:
module.fail_json(msg="Failed to get Kibana version : %s" % err)
return out.strip()
def main(): def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
@ -213,22 +237,26 @@ def main():
version = module.params["version"] version = module.params["version"]
force = module.params["force"] force = module.params["force"]
changed, cmd, out, err = False, '', '', ''
kibana_version = get_kibana_version(module, plugin_bin)
present = is_plugin_present(parse_plugin_repo(name), plugin_dir) present = is_plugin_present(parse_plugin_repo(name), plugin_dir)
# skip if the state is correct # skip if the state is correct
if (present and state == "present" and not force) or (state == "absent" and not present and not force): if (present and state == "present" and not force) or (state == "absent" and not present and not force):
module.exit_json(changed=False, name=name, state=state) module.exit_json(changed=False, name=name, state=state)
if (version): if version:
name = name + '/' + version name = name + '/' + version
if state == "present": if state == "present":
if force: if force:
remove_plugin(module, plugin_bin, name) remove_plugin(module, plugin_bin, name)
changed, cmd, out, err = install_plugin(module, plugin_bin, name, url, timeout) changed, cmd, out, err = install_plugin(module, plugin_bin, name, url, timeout, kibana_version)
elif state == "absent": elif state == "absent":
changed, cmd, out, err = remove_plugin(module, plugin_bin, name) changed, cmd, out, err = remove_plugin(module, plugin_bin, name, kibana_version)
module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err) module.exit_json(changed=changed, cmd=cmd, name=name, state=state, url=url, timeout=timeout, stdout=out, stderr=err)