diff --git a/lib/ansible/module_utils/network/f5/bigip.py b/lib/ansible/module_utils/network/f5/bigip.py index 4db7c8576c..5174b699c0 100644 --- a/lib/ansible/module_utils/network/f5/bigip.py +++ b/lib/ansible/module_utils/network/f5/bigip.py @@ -16,19 +16,27 @@ except ImportError: try: from library.module_utils.network.f5.common import F5BaseClient + from library.module_utils.network.f5.common import F5ModuleError except ImportError: from ansible.module_utils.network.f5.common import F5BaseClient + from ansible.module_utils.network.f5.common import F5ModuleError class F5Client(F5BaseClient): @property def api(self): - result = ManagementRoot( - self.params['server'], - self.params['user'], - self.params['password'], - port=self.params['server_port'], - verify=self.params['validate_certs'], - token='tmos' - ) + try: + result = ManagementRoot( + self.params['server'], + self.params['user'], + self.params['password'], + port=self.params['server_port'], + verify=self.params['validate_certs'], + token='tmos' + ) + except Exception: + raise F5ModuleError( + 'Unable to connect to {0} on port {1}. ' + 'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port']) + ) return result diff --git a/lib/ansible/module_utils/network/f5/bigiq.py b/lib/ansible/module_utils/network/f5/bigiq.py index 5e23645835..80fd866835 100644 --- a/lib/ansible/module_utils/network/f5/bigiq.py +++ b/lib/ansible/module_utils/network/f5/bigiq.py @@ -14,18 +14,29 @@ try: except ImportError: HAS_F5SDK = False -from ansible.module_utils.network.f5.common import F5BaseClient +try: + from library.module_utils.network.f5.common import F5BaseClient + from library.module_utils.network.f5.common import F5ModuleError +except ImportError: + from ansible.module_utils.network.f5.common import F5BaseClient + from ansible.module_utils.network.f5.common import F5ModuleError class F5Client(F5BaseClient): @property def api(self): - result = ManagementRoot( - self.params['server'], - self.params['user'], - self.params['password'], - port=self.params['server_port'], - verify=self.params['validate_certs'], - token='local' - ) + try: + result = ManagementRoot( + self.params['server'], + self.params['user'], + self.params['password'], + port=self.params['server_port'], + verify=self.params['validate_certs'], + token='local' + ) + except Exception: + raise F5ModuleError( + 'Unable to connect to {0} on port {1}. ' + 'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port']) + ) return result diff --git a/lib/ansible/module_utils/network/f5/iworkflow.py b/lib/ansible/module_utils/network/f5/iworkflow.py index 96fea1dcd7..903b57478e 100644 --- a/lib/ansible/module_utils/network/f5/iworkflow.py +++ b/lib/ansible/module_utils/network/f5/iworkflow.py @@ -14,18 +14,29 @@ try: except ImportError: HAS_F5SDK = False -from ansible.module_utils.network.f5.common import F5BaseClient +try: + from library.module_utils.network.f5.common import F5BaseClient + from library.module_utils.network.f5.common import F5ModuleError +except ImportError: + from ansible.module_utils.network.f5.common import F5BaseClient + from ansible.module_utils.network.f5.common import F5ModuleError class F5Client(F5BaseClient): @property def api(self): - result = ManagementRoot( - self.params['server'], - self.params['user'], - self.params['password'], - port=self.params['server_port'], - verify=self.params['validate_certs'], - token='local' - ) + try: + result = ManagementRoot( + self.params['server'], + self.params['user'], + self.params['password'], + port=self.params['server_port'], + verify=self.params['validate_certs'], + token='local' + ) + except Exception: + raise F5ModuleError( + 'Unable to connect to {0} on port {1}. ' + 'Is "validate_certs" preventing this?'.format(self.params['server'], self.params['server_port']) + ) return result