From 9ebad79f400084ddf088bf74f37c6681cd05efaf Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 16 Apr 2018 07:35:51 +0530 Subject: [PATCH] influxdb: Add condition for retries argument (#38441) 'retries' argument was added to InfluxDBClient in version 4.1.0, versions lower than this fails if retries are specified. This fix adds a conditional to check if version is greater than equal to 4.1.0 and depending upon that adds 'retries' option. Fixes: #38204 Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/influxdb.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/influxdb.py b/lib/ansible/module_utils/influxdb.py index a1762bde586..da43604e8f9 100644 --- a/lib/ansible/module_utils/influxdb.py +++ b/lib/ansible/module_utils/influxdb.py @@ -13,6 +13,7 @@ except ImportError: try: from influxdb import InfluxDBClient + from influxdb import __version__ as influxdb_version from influxdb import exceptions HAS_INFLUXDB = True except ImportError: @@ -54,7 +55,7 @@ class InfluxDb(): ) def connect_to_influxdb(self): - return InfluxDBClient( + args = dict( host=self.hostname, port=self.port, username=self.username, @@ -63,8 +64,13 @@ class InfluxDb(): ssl=self.params['ssl'], verify_ssl=self.params['validate_certs'], timeout=self.params['timeout'], - retries=self.params['retries'], use_udp=self.params['use_udp'], udp_port=self.params['udp_port'], proxies=self.params['proxies'], ) + influxdb_api_version = tuple(influxdb_version.split(".")) + if influxdb_api_version >= ('4', '1', '0'): + # retries option is added in version 4.1.0 + args.update(retries=self.params['retries']) + + return InfluxDBClient(**args)