mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-05 16:04:09 -07:00
Switch etcd and url lookup plugins to verify ssl certificates
This commit is contained in:
parent
4161d78a94
commit
77c76e632e
2 changed files with 27 additions and 17 deletions
|
@ -17,30 +17,36 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
import urllib2
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
|
||||
from ansible.utils.unicode import to_unicode
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
||||
|
||||
def run(self, terms, inject=None, **kwargs):
|
||||
def run(self, terms, variables=None, **kwargs):
|
||||
|
||||
if isinstance(terms, basestring):
|
||||
terms = [ terms ]
|
||||
|
||||
validate_certs = kwargs.get('validate_certs', True)
|
||||
|
||||
ret = []
|
||||
for term in terms:
|
||||
try:
|
||||
r = urllib2.Request(term)
|
||||
response = urllib2.urlopen(r)
|
||||
except URLError as e:
|
||||
utils.warnings("Failed lookup url for %s : %s" % (term, str(e)))
|
||||
continue
|
||||
except HTTPError as e:
|
||||
utils.warnings("Received HTTP error for %s : %s" % (term, str(e)))
|
||||
continue
|
||||
response = open_url(term, validate_certs=validate_certs)
|
||||
except urllib2.URLError as e:
|
||||
raise AnsibleError("Failed lookup url for %s : %s" % (term, str(e)))
|
||||
except urllib2.HTTPError as e:
|
||||
raise AnsibleError("Received HTTP error for %s : %s" % (term, str(e)))
|
||||
except SSLValidationError as e:
|
||||
raise AnsibleError("Error validating the server's certificate for %s: %s" % (term, str(e)))
|
||||
except ConnectionError as e:
|
||||
raise AnsibleError("Error connecting to %s: %s" % (term, str(e)))
|
||||
|
||||
for line in response.read().splitlines():
|
||||
ret.append(line)
|
||||
|
||||
ret.append(to_unicode(line))
|
||||
return ret
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue