Convert results with to_native in consul_kv plugin (#46551)

* #42851 convert results with to_native

* added missing ANSIBLE_METADATA

* removed unneeded brackets

* * replaced to_native with to_text to avoid getting bytecode
This commit is contained in:
Johannes Brunswicker 2018-10-11 15:35:49 +02:00 committed by Brian Coca
commit b3063e37be

View file

@ -5,6 +5,10 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """ DOCUMENTATION = """
lookup: consul_kv lookup: consul_kv
version_added: "1.9" version_added: "1.9"
@ -99,8 +103,7 @@ import os
from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.six.moves.urllib.parse import urlparse
from ansible.errors import AnsibleError, AnsibleAssertionError from ansible.errors import AnsibleError, AnsibleAssertionError
from ansible.plugins.lookup import LookupBase from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_text
import json
try: try:
import consul import consul
@ -146,9 +149,9 @@ class LookupModule(LookupBase):
# responds with a single or list of result maps # responds with a single or list of result maps
if isinstance(results[1], list): if isinstance(results[1], list):
for r in results[1]: for r in results[1]:
values.append(r['Value']) values.append(to_text(r['Value']))
else: else:
values.append(results[1]['Value']) values.append(to_text(results[1]['Value']))
except Exception as e: except Exception as e:
raise AnsibleError( raise AnsibleError(
"Error locating '%s' in kv store. Error was %s" % (term, e)) "Error locating '%s' in kv store. Error was %s" % (term, e))