From ed405371f021cf715189d728695d81b24f0faa78 Mon Sep 17 00:00:00 2001 From: abhinavbansal29 Date: Mon, 7 Oct 2024 16:20:12 +0530 Subject: [PATCH] Added Error message for dynamic inventory if wrong credentials are passed Issue: https://github.com/nutanix/nutanix.ansible/issues/421 --- plugins/module_utils/entity.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/module_utils/entity.py b/plugins/module_utils/entity.py index b4c25670..96df2001 100644 --- a/plugins/module_utils/entity.py +++ b/plugins/module_utils/entity.py @@ -18,6 +18,9 @@ from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse except ImportError: from urlparse import urlparse # python2 +from ansible.utils.display import Display + +display = Display() class Entity(object): @@ -174,6 +177,11 @@ def list( no_response=no_response, timeout=timeout, ) + if resp and resp.get("state") == "ERROR" and resp.get("code") == 401: + display.error( + "Failed fetching URL: {0}, error={1}".format(url, resp["message_list"]) + ) + exit(1) if resp: custom_filters = self.module.params.get("custom_filter")