nutanix / nutanix.ansible

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

[Bug] Error when Clusters Block is missing in module ntnx_foundation #397

Closed rthunt closed 10 months ago

rthunt commented 11 months ago

Describe the bug When omitting the clusters: block section from the ntnx_foundation module the playbook throws an error however Foundation works as intended and only images the nodes. No errors occur in foundation.

The Clusters: block is marked as "not required" but the error that throws when NOT having it configured is forcing the Playbook to fail.

To Reproduce Steps to reproduce the behavior:

  1. ansible-playbook image_nodes.yaml

Playbook:

---
- name: Image Nodes
  hosts: localhost
  gather_facts: false
  collections:
    - nutanix.ncp

  tasks:
  - name: Image nodes using manual modes
    ntnx_foundation:
      timeout: 4500
      nutanix_host: "{{ foundation_ip }}" #Foundation Server
      cvm_gateway: "{{ cvm_gateway }}"
      cvm_netmask: "{{ cvm_netmask }}"
      hypervisor_gateway: "{{ hypervisor_gateway }}"
      hypervisor_netmask: "{{ hypervisor_netmask }}"
      ipmi_gateway: "{{ ipmi_gateway }}"
      ipmi_netmask: "{{ ipmi_netmask"
      bond_mode: "{{ bond_mode }}"
      default_ipmi_user: "{{ nx_admin_user }}"
      default_ipmi_password: "{{ nx_ipmi_admin_password }}"
      bond_lacp_rate: "{{ bond_lacp_rate }}"
      current_cvm_vlan_tag: "{{ current_cvm_vlan_tag }}"
      nos_package: "{{ aos_package }}"
      blocks:
        - block_id: ""
          nodes:
            - manual_mode:
                node_serial: ""
                cvm_gb_ram: 32
                ipmi_ip: "10.XX.XX.XX"
                hypervisor_ip: "10.XX.XX.xx"
                cvm_ip: "10.XX.XX.XX"
                hypervisor: "kvm"
                hypervisor_hostname: "node001"
                node_position: "A"
                #ipmi_user: "{{ nx_admin_user }}"
                #ipmi_password: "{{ nx_ipmi_admin_password }}"
            - manual_mode:
                node_serial: ""
                cvm_gb_ram: 32
                 ipmi_ip: "10.XX.XX.XX"
                hypervisor_ip: "10.XX.XX.xx"
                cvm_ip: "10.XX.XX.XX"
                hypervisor: "kvm"
                hypervisor_hostname: "node002"
                node_position: "B"
        - block_id: ""
          nodes:
            - manual_mode:
                node_serial: ""
                cvm_gb_ram: 32
                ipmi_ip: "10.XX.XX.XX"
                hypervisor_ip: "10.XX.XX.xx"
                cvm_ip: "10.XX.XX.XX"
                hypervisor: "kvm"
                hypervisor_hostname: "node003"
                node_position: "A"
            - manual_mode:
                node_serial: ""
                cvm_gb_ram: 32
                ipmi_ip: "10.XX.XX.XX"
                hypervisor_ip: "10.XX.XX.xx"
                cvm_ip: "10.XX.XX.XX"
                hypervisor: "kvm"
                hypervisor_hostname: "node004"
                node_position: "B"
    register: output

  - debug:
      msg: '{{ output }}'

Stack trace

The full traceback is:

Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_foundation', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_foundation', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py", line 1290, in <module>
  File "/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py", line 1286, in main
  File "/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py", line 1281, in run_module
  File "/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py", line 1247, in image_nodes
KeyError: 'clusters'
[WARNING]: Platform linux on host localhost is using the discovered Python interpreter at
/root/data/solutions/nutanix/nutanix.ansible/venv/bin/python3.11, but future installation of another
Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-
core/2.14/reference_appendices/interpreter_discovery.html for more information.
fatal: [localhost]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/root/data/solutions/nutanix/nutanix.ansible/venv/bin/python3.11"
    },
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1694716468.608142-1548-105664984499090/AnsiballZ_ntnx_foundation.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_foundation', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_foundation', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py\", line 1290, in <module>\n  File \"/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py\", line 1286, in main\n  File \"/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py\", line 1281, in run_module\n  File \"/tmp/ansible_ntnx_foundation_payload_0cmazq9c/ansible_ntnx_foundation_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_foundation.py\", line 1247, in image_nodes\nKeyError: 'clusters'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Expected behavior When the Clusters Block is omitted (since it is not required) the expectation is that Foundation completes imaging the nodes, a cluster is not created, and the success message is displayed via the ansible output.

Additional context

bhati-pradeep commented 10 months ago

Fixed in release v1.9.1