Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Error message for dynamic inventory if wrong credentials are passed #512

Open
wants to merge 3 commits into
base: release/1.9.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugins/inventory/ntnx_prism_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable # noqa: E402

from ..module_utils.prism import vms # noqa: E402
import sys


class Mock_Module:
Expand All @@ -91,6 +92,13 @@ def __init__(self, host, port, username, password, validate_certs=False):
def jsonify(self, data):
return json.dumps(data)

def fail_json(self, msg, **kwargs):
"""Fail with a message"""
kwargs["failed"] = True
kwargs["msg"] = msg
print("\n%s" % self.jsonify(kwargs))
sys.exit(1)


class InventoryModule(BaseInventoryPlugin, Constructable):
"""Nutanix VM dynamic inventory module for ansible"""
Expand Down
9 changes: 9 additions & 0 deletions plugins/module_utils/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ def list(
no_response=no_response,
timeout=timeout,
)
if resp and resp.get("state") == "ERROR":
if raise_error:
self.module.fail_json(
msg="Failed fetching URL: {0}".format(url),
error=resp.get("message_list"),
response=resp,
)
else:
return resp
if resp:
custom_filters = self.module.params.get("custom_filter")

Expand Down
Loading