From 79eeea8ea6289b29ed55361813f2179f005b7332 Mon Sep 17 00:00:00 2001 From: Jad Kik Date: Wed, 27 Feb 2019 13:04:18 +0200 Subject: [PATCH] lookup: redis: fix plugin returning repr'd byte objects (#52854) * Fix default port of redis lookup plugin * Fix redis plugin returning repr'd byte objects * Fix error handling in redis lookup plugin --- lib/ansible/plugins/lookup/redis.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/lookup/redis.py b/lib/ansible/plugins/lookup/redis.py index fc5036525c9..fdb49110b8c 100644 --- a/lib/ansible/plugins/lookup/redis.py +++ b/lib/ansible/plugins/lookup/redis.py @@ -28,7 +28,7 @@ DOCUMENTATION = """ key: host port: description: port on which Redis is listening on - default: 6379A + default: 6379 type: int env: - name: ANSIBLE_REDIS_PORT @@ -75,6 +75,7 @@ try: except ImportError: pass +from ansible.module_utils._text import to_text from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase @@ -104,7 +105,8 @@ class LookupModule(LookupBase): res = conn.get(term) if res is None: res = "" - ret.append(res) - except Exception: - ret.append("") # connection failed or key not found + ret.append(to_text(res)) + except Exception as e: + # connection failed or key not found + raise AnsibleError('Encountered exception while fetching {0}: {1}'.format(term, e)) return ret