mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 23:51:23 -07:00
moved to use 'get_option'
also fixed bad str() usage
This commit is contained in:
parent
f0463befc7
commit
44d4327bc7
1 changed files with 8 additions and 10 deletions
|
@ -44,7 +44,7 @@ RETURN = """
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
|
||||||
from ansible.module_utils._text import to_text
|
from ansible.module_utils._text import to_text, to_native
|
||||||
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
|
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
|
||||||
|
@ -59,25 +59,23 @@ class LookupModule(LookupBase):
|
||||||
|
|
||||||
def run(self, terms, variables=None, **kwargs):
|
def run(self, terms, variables=None, **kwargs):
|
||||||
|
|
||||||
validate_certs = kwargs.get('validate_certs', True)
|
self.set_options(direct=kwargs)
|
||||||
split_lines = kwargs.get('split_lines', True)
|
|
||||||
use_proxy = kwargs.get('use_proxy', True)
|
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
for term in terms:
|
for term in terms:
|
||||||
display.vvvv("url lookup connecting to %s" % term)
|
display.vvvv("url lookup connecting to %s" % term)
|
||||||
try:
|
try:
|
||||||
response = open_url(term, validate_certs=validate_certs, use_proxy=use_proxy)
|
response = open_url(term, validate_certs=self.get_option('validate_certs'), use_proxy=self.get_option('use_proxy'))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
raise AnsibleError("Received HTTP error for %s : %s" % (term, str(e)))
|
raise AnsibleError("Received HTTP error for %s : %s" % (term, to_native(e)))
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
raise AnsibleError("Failed lookup url for %s : %s" % (term, str(e)))
|
raise AnsibleError("Failed lookup url for %s : %s" % (term, to_native(e)))
|
||||||
except SSLValidationError as e:
|
except SSLValidationError as e:
|
||||||
raise AnsibleError("Error validating the server's certificate for %s: %s" % (term, str(e)))
|
raise AnsibleError("Error validating the server's certificate for %s: %s" % (term, to_native(e)))
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
raise AnsibleError("Error connecting to %s: %s" % (term, str(e)))
|
raise AnsibleError("Error connecting to %s: %s" % (term, to_native(e)))
|
||||||
|
|
||||||
if split_lines:
|
if self.get_option('split_lines'):
|
||||||
for line in response.read().splitlines():
|
for line in response.read().splitlines():
|
||||||
ret.append(to_text(line))
|
ret.append(to_text(line))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue