nutanix / nutanix.ansible

Official Nutanix Ansible collections
GNU General Public License v3.0
64 stars 36 forks source link

[Bug] API failure is not in shown while creating dynamic inventory #421

Open bhati-pradeep opened 10 months ago

bhati-pradeep commented 10 months ago

Describe the bug During API failure, the inventory plugin gives warning about some code error in entity.py and returns empty response.

To Reproduce Steps to reproduce the behavior:

  1. Create dynamic inventory with wrong creds.

Stack trace

~/work/codebase/nutanix/nutanix.ansible/inventory-example imprv/issue#409 *57 !1 ?19 ❯ ansible-inventory  --list -vvvv                                                                                                            12:44:44 AM
ansible-inventory [core 2.13.0]
  config file = /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/ansible.cfg
  configured module search path = ['/Users/pradeep.bhati/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/pradeep.bhati/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.9.16 (main, Dec  7 2022, 10:15:43) [Clang 14.0.0 (clang-1400.0.29.202)]
  jinja version = 3.1.1
  libyaml = True
Using /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/ansible.cfg as config file
setting up inventory plugins
Loading collection nutanix.ncp from /Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp
[WARNING]:  * Failed to parse /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/nutanix.yml with ansible_collections.nutanix.ncp.plugins.inventory.ntnx_prism_vm_inventory plugin: 'Mock_Module' object has no
attribute 'fail_json'
  File "/usr/local/lib/python3.9/site-packages/ansible/inventory/manager.py", line 290, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/inventory/ntnx_prism_vm_inventory.py", line 143, in parse
    resp = vm.list(self.data)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py", line 81, in list
    resp = super(VM, self).list(data)
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py", line 198, in list
    resp = self._fetch_url(
  File "/Users/pradeep.bhati/.ansible/collections/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py", line 410, in _fetch_url
    self.module.fail_json(
[WARNING]: Unable to parse /Users/pradeep.bhati/Work/codebase/nutanix/nutanix.ansible/inventory-example/nutanix.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

Expected behavior A clear API failure with message should be shown.

Additional context

Script:

ansible.cfg ->

[defaults]
inventory = nutanix.yml

[inventory]
enable_plugins = nutanix.ncp.ntnx_prism_vm_inventory

nutanix.yml ->

plugin: nutanix.ncp.ntnx_prism_vm_inventory
nutanix_hostname: IP address of PC
nutanix_password: password
nutanix_username: username
nutanix_port: 9440
validate_certs: false