mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-06 09:11:29 -07:00
grafana_plugin: Add check condition when plugin version is 'latest' (#53369)
* Add check condition when plugin version is 'latest' * Add check condition when plugin version is 'latest' + pep 8
This commit is contained in:
parent
6661f17ce3
commit
24c5a6ef4c
1 changed files with 22 additions and 0 deletions
|
@ -136,6 +136,23 @@ def get_grafana_plugin_version(module, params):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_grafana_plugin_version_latest(module, params):
|
||||||
|
'''
|
||||||
|
Fetch the latest version available from grafana-cli.
|
||||||
|
Return the newest version number or None not found.
|
||||||
|
|
||||||
|
:param module: ansible module object. used to run system commands.
|
||||||
|
:param params: ansible module params.
|
||||||
|
'''
|
||||||
|
grafana_cli = grafana_cli_bin(params)
|
||||||
|
rc, stdout, stderr = module.run_command('{0} list-versions {1}'.format(grafana_cli,
|
||||||
|
params['name']))
|
||||||
|
stdout_lines = stdout.split("\n")
|
||||||
|
if stdout_lines[0]:
|
||||||
|
return stdout_lines[0].rstrip()
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def grafana_plugin(module, params):
|
def grafana_plugin(module, params):
|
||||||
'''
|
'''
|
||||||
Install update or remove grafana plugin
|
Install update or remove grafana plugin
|
||||||
|
@ -155,6 +172,11 @@ def grafana_plugin(module, params):
|
||||||
'version': grafana_plugin_version}
|
'version': grafana_plugin_version}
|
||||||
else:
|
else:
|
||||||
if params['version'] == 'latest' or params['version'] is None:
|
if params['version'] == 'latest' or params['version'] is None:
|
||||||
|
latest_version = get_grafana_plugin_version_latest(module, params)
|
||||||
|
if latest_version == grafana_plugin_version:
|
||||||
|
return {'msg': 'Grafana plugin already installed',
|
||||||
|
'changed': False,
|
||||||
|
'version': grafana_plugin_version}
|
||||||
cmd = '{0} update {1}'.format(grafana_cli, params['name'])
|
cmd = '{0} update {1}'.format(grafana_cli, params['name'])
|
||||||
else:
|
else:
|
||||||
cmd = '{0} install {1} {2}'.format(grafana_cli, params['name'], params['version'])
|
cmd = '{0} install {1} {2}'.format(grafana_cli, params['name'], params['version'])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue