From ce0f3278750d51f5b1a7004ace78a838d33f7e57 Mon Sep 17 00:00:00 2001 From: Mathias Ettinger Date: Fri, 6 Nov 2020 09:12:00 +0100 Subject: [PATCH] InfluxDB_database: Make the path argument conditional on the InfluxDB version (#1126) Co-authored-by: Mathias Ettinger --- .../1126-influxdb-conditional-path-argument.yml | 4 ++++ plugins/doc_fragments/influxdb.py | 2 ++ plugins/module_utils/influxdb.py | 10 +++++++--- plugins/modules/database/influxdb/influxdb_database.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/1126-influxdb-conditional-path-argument.yml diff --git a/changelogs/fragments/1126-influxdb-conditional-path-argument.yml b/changelogs/fragments/1126-influxdb-conditional-path-argument.yml new file mode 100644 index 0000000000..ec5cb1f63e --- /dev/null +++ b/changelogs/fragments/1126-influxdb-conditional-path-argument.yml @@ -0,0 +1,4 @@ +--- +bugfixes: + - influxdb - fix usage of path for older version of + python-influxdb (https://github.com/ansible-collections/community.general/issues/997). diff --git a/plugins/doc_fragments/influxdb.py b/plugins/doc_fragments/influxdb.py index 2e0210b819..3ed208f3cb 100644 --- a/plugins/doc_fragments/influxdb.py +++ b/plugins/doc_fragments/influxdb.py @@ -40,6 +40,7 @@ options: path: description: - The path on which InfluxDB server is accessible + - Only available when using python-influxdb >= 5.1.0 type: str version_added: '0.2.0' validate_certs: @@ -60,6 +61,7 @@ options: description: - Number of retries client will try before aborting. - C(0) indicates try until success. + - Only available when using python-influxdb >= 4.1.0 type: int default: 3 use_udp: diff --git a/plugins/module_utils/influxdb.py b/plugins/module_utils/influxdb.py index 0bdd4e6cdd..92c7802335 100644 --- a/plugins/module_utils/influxdb.py +++ b/plugins/module_utils/influxdb.py @@ -9,6 +9,7 @@ __metaclass__ = type import traceback from ansible.module_utils.basic import missing_required_lib +from distutils.version import LooseVersion REQUESTS_IMP_ERR = None try: @@ -69,7 +70,6 @@ class InfluxDb(): args = dict( host=self.hostname, port=self.port, - path=self.path, username=self.username, password=self.password, database=self.database_name, @@ -80,9 +80,13 @@ class InfluxDb(): udp_port=self.params['udp_port'], proxies=self.params['proxies'], ) - influxdb_api_version = tuple(influxdb_version.split(".")) - if influxdb_api_version >= ('4', '1', '0'): + influxdb_api_version = LooseVersion(influxdb_version) + if influxdb_api_version >= LooseVersion('4.1.0'): # retries option is added in version 4.1.0 args.update(retries=self.params['retries']) + if influxdb_api_version >= LooseVersion('5.1.0'): + # path argument is added in version 5.1.0 + args.update(path=self.path) + return InfluxDBClient(**args) diff --git a/plugins/modules/database/influxdb/influxdb_database.py b/plugins/modules/database/influxdb/influxdb_database.py index d370046de1..7b798c3679 100644 --- a/plugins/modules/database/influxdb/influxdb_database.py +++ b/plugins/modules/database/influxdb/influxdb_database.py @@ -16,7 +16,7 @@ description: author: "Kamil Szczygiel (@kamsz)" requirements: - "python >= 2.6" - - "influxdb >= 0.9 & <= 1.2.4" + - "influxdb >= 0.9" - requests options: database_name: