mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Validate SSL certs accessed through urllib*
* Adds another module utility file which generalizes the access of urls via the urllib* libraries. * Adds a new spec generator for common arguments. * Makes the user-agent string configurable. Fixes #6211
This commit is contained in:
@@ -96,31 +96,12 @@ EXAMPLES = '''
|
||||
tags=tag1,tag2,tag3
|
||||
'''
|
||||
|
||||
HAS_URLLIB = True
|
||||
try:
|
||||
import urllib
|
||||
except ImportError:
|
||||
HAS_URLLIB = False
|
||||
|
||||
HAS_URLLIB2 = True
|
||||
try:
|
||||
import urllib2
|
||||
except ImportError:
|
||||
HAS_URLLIB2 = False
|
||||
|
||||
|
||||
|
||||
# ===========================================
|
||||
# Module execution.
|
||||
#
|
||||
|
||||
def main():
|
||||
|
||||
if not HAS_URLLIB:
|
||||
module.fail_json(msg="urllib is not installed")
|
||||
if not HAS_URLLIB2:
|
||||
module.fail_json(msg="urllib2 is not installed")
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
token=dict(required=True),
|
||||
@@ -187,14 +168,16 @@ def main():
|
||||
module.exit_json(changed=False)
|
||||
|
||||
# Send the data to Flowdock
|
||||
try:
|
||||
response = urllib2.urlopen(url, urllib.urlencode(params))
|
||||
except Exception, e:
|
||||
module.fail_json(msg="unable to send msg: %s" % e)
|
||||
data = urllib.urlencode(params)
|
||||
response, info = fetch_url(module, url, data=data)
|
||||
if info['status'] != 200:
|
||||
module.fail_json(msg="unable to send msg: %s" % info['msg'])
|
||||
|
||||
module.exit_json(changed=False, msg=module.params["msg"])
|
||||
module.exit_json(changed=True, msg=module.params["msg"])
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.urls import *
|
||||
|
||||
main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user