From 908697e121ee287e00a0369e9d6141456df9fba0 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Tue, 3 May 2016 22:50:45 -0700 Subject: [PATCH] Reverse the unpack list operation Instead of doing an unpack, deliberately specify which parameters you want to use. This allows us to flexibly add more parameters to the f5_argument_spec without having to rewrite all the modules that use it. Functionally this commit changes nothing, it just provides for a different way of accessing the parameters to the module --- .../extras/network/f5/bigip_monitor_http.py | 15 ++++++++++++++- .../extras/network/f5/bigip_monitor_tcp.py | 17 +++++++++++++++-- .../modules/extras/network/f5/bigip_node.py | 17 +++++++++++++++-- .../modules/extras/network/f5/bigip_pool.py | 15 ++++++++++++++- .../extras/network/f5/bigip_pool_member.py | 18 ++++++++++++++++-- .../extras/network/f5/bigip_virtual_server.py | 16 +++++++++++++++- 6 files changed, 89 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/extras/network/f5/bigip_monitor_http.py b/lib/ansible/modules/extras/network/f5/bigip_monitor_http.py index d74cf65602..ab5c704b49 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_monitor_http.py +++ b/lib/ansible/modules/extras/network/f5/bigip_monitor_http.py @@ -317,7 +317,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] parent_partition = module.params['parent_partition'] name = module.params['name'] diff --git a/lib/ansible/modules/extras/network/f5/bigip_monitor_tcp.py b/lib/ansible/modules/extras/network/f5/bigip_monitor_tcp.py index 418c2562f8..1f8a9eead9 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_monitor_tcp.py +++ b/lib/ansible/modules/extras/network/f5/bigip_monitor_tcp.py @@ -315,7 +315,7 @@ def set_ipport(api, monitor, ipport): def main(): # begin monitor specific stuff - argument_spec=f5_argument_spec(); + argument_spec=f5_argument_spec() argument_spec.update(dict( name = dict(required=True), type = dict(default=DEFAULT_TEMPLATE_TYPE_CHOICE, choices=TEMPLATE_TYPE_CHOICES), @@ -336,7 +336,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] parent_partition = module.params['parent_partition'] name = module.params['name'] diff --git a/lib/ansible/modules/extras/network/f5/bigip_node.py b/lib/ansible/modules/extras/network/f5/bigip_node.py index 9cd8d2a3ac..732ec6c191 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_node.py +++ b/lib/ansible/modules/extras/network/f5/bigip_node.py @@ -263,7 +263,7 @@ def get_node_monitor_status(api, name): def main(): - argument_spec=f5_argument_spec(); + argument_spec=f5_argument_spec() argument_spec.update(dict( session_state = dict(type='str', choices=['enabled', 'disabled']), monitor_state = dict(type='str', choices=['enabled', 'disabled']), @@ -278,7 +278,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] diff --git a/lib/ansible/modules/extras/network/f5/bigip_pool.py b/lib/ansible/modules/extras/network/f5/bigip_pool.py index 77d99760a8..7a327d680d 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_pool.py +++ b/lib/ansible/modules/extras/network/f5/bigip_pool.py @@ -367,7 +367,20 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] name = module.params['name'] pool = fq_name(partition,name) diff --git a/lib/ansible/modules/extras/network/f5/bigip_pool_member.py b/lib/ansible/modules/extras/network/f5/bigip_pool_member.py index 7245235007..d97929462a 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_pool_member.py +++ b/lib/ansible/modules/extras/network/f5/bigip_pool_member.py @@ -342,7 +342,7 @@ def get_member_monitor_status(api, pool, address, port): return result def main(): - argument_spec = f5_argument_spec(); + argument_spec = f5_argument_spec() argument_spec.update(dict( session_state = dict(type='str', choices=['enabled', 'disabled']), monitor_state = dict(type='str', choices=['enabled', 'disabled']), @@ -362,7 +362,21 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] + session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] pool = fq_name(partition, module.params['pool']) diff --git a/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py b/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py index 68d6e116b8..a59a4ed0be 100644 --- a/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py +++ b/lib/ansible/modules/extras/network/f5/bigip_virtual_server.py @@ -392,7 +392,21 @@ def main(): supports_check_mode=True ) - (server,user,password,state,partition,validate_certs) = f5_parse_arguments(module) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + + 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') + + server = module.params['server'] + user = module.params['user'] + password = module.params['password'] + state = module.params['state'] + partition = module.params['partition'] + validate_certs = module.params['validate_certs'] + name = fq_name(partition,module.params['name']) destination=module.params['destination'] port=module.params['port']