From 80967380d3642081b424eb95f9c1f83881438b9f Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 8 Nov 2017 20:48:22 +0000 Subject: [PATCH] Add error handling for user login (#32613) This fix adds additional error handling for vmware connect method, where username provided user does not have required permissions to use/login ESXi. Signed-off-by: Abhijeet Kasurde --- lib/ansible/module_utils/vmware.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 2fac709d9f..baa5b06506 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -414,6 +414,9 @@ def connect_to_api(module, disconnect_atexit=True): service_instance = connect.SmartConnect(host=hostname, user=username, pwd=password, sslContext=ssl_context) except vim.fault.InvalidLogin as e: module.fail_json(msg="Unable to log on to vCenter or ESXi API at %s as %s: %s" % (hostname, username, e.msg)) + except vim.fault.NoPermission as e: + module.fail_json(msg="User %s does not have required permission" + " to log on to vCenter or ESXi API at %s: %s" % (username, hostname, e.msg)) except (requests.ConnectionError, ssl.SSLError) as e: module.fail_json(msg="Unable to connect to vCenter or ESXi API at %s on TCP/443: %s" % (hostname, e)) except Exception as e: