summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-12-24 11:32:40 -0800
committerToshio Kuratomi <toshio@fedoraproject.org>2015-12-24 11:49:31 -0800
commitdeac4d00b22f9e0288f5e3c4633e07a7f937d47c (patch)
treebfa163aef7e87d9336aa8ac419477a11036eedf1
parentfd7e01696f659e1a147887087c87e2bad9742209 (diff)
downloadansible-f5-remove-global-ssl-disable.tar.gz
bigip changes as requested by bcoca and abadger:f5-remove-global-ssl-disable
* Fix to error if validate_cert is True and python doesn't support it. * Only globally disable certificate checking if really needed. Use bigip verify parameter if available instead. * Remove public disable certificate function to make it less likely people will attempt to reuse that
-rw-r--r--lib/ansible/module_utils/f5.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/lib/ansible/module_utils/f5.py b/lib/ansible/module_utils/f5.py
index e04e6b2f1e..ba336377e7 100644
--- a/lib/ansible/module_utils/f5.py
+++ b/lib/ansible/module_utils/f5.py
@@ -51,19 +51,35 @@ def f5_argument_spec():
def f5_parse_arguments(module):
if not bigsuds_found:
module.fail_json(msg="the python bigsuds module is required")
- if not module.params['validate_certs']:
- disable_ssl_cert_validation()
+
+ if module.params['validate_certs']:
+ import ssl
+ if not hasattr(ssl, 'SSLContext'):
+ module.fail_json(msg='bigsuds does not support verifying certificates with python < 2.7.9. Either update python or set validate_certs=False on the task')
+
return (module.params['server'],module.params['user'],module.params['password'],module.params['state'],module.params['partition'],module.params['validate_certs'])
-def bigip_api(bigip, user, password):
- api = bigsuds.BIGIP(hostname=bigip, username=user, password=password)
- return api
+def bigip_api(bigip, user, password, validate_certs):
+ try:
+ # bigsuds >= 1.0.3
+ api = bigsuds.BIGIP(hostname=bigip, username=user, password=password, verify=validate_certs)
+ except TypeError:
+ # bigsuds < 1.0.3, no verify param
+ if validate_certs:
+ # Note: verified we have SSLContext when we parsed params
+ api = bigsuds.BIGIP(hostname=bigip, username=user, password=password)
+ else:
+ import ssl
+ if hasattr(ssl, 'SSLContext'):
+ # Really, you should never do this. It disables certificate
+ # verification *globally*. But since older bigip libraries
+ # don't give us a way to toggle verification we need to
+ # disable it at the global level.
+ # From https://www.python.org/dev/peps/pep-0476/#id29
+ ssl._create_default_https_context = ssl._create_unverified_context
+ api = bigsuds.BIGIP(hostname=bigip, username=user, password=password)
-def disable_ssl_cert_validation():
- # You probably only want to do this for testing and never in production.
- # From https://www.python.org/dev/peps/pep-0476/#id29
- import ssl
- ssl._create_default_https_context = ssl._create_unverified_context
+ return api
# Fully Qualified name (with the partition)
def fq_name(partition,name):