nutanix / nutanix.ansible

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

[Bug] cannot change boot_config when cloning in module ntnx_vms_clone #360

Closed chriswolske closed 10 months ago

chriswolske commented 1 year ago

Describe the bug When attempting to clone a VM and change the boot_config in the process, the module throws an error. The original VM is LEGACY and I want the new VM to use EUFI. The reason I'm using a clone is because it is not possible to switch the boot config from LEGACY to EUFI after a VM has been created; I thought this would be a work-around to that.

To Reproduce Steps to reproduce the behavior:

    - name: Clone the VM
      delegate_to: localhost
      ntnx_vms_clone:
        src_vm_uuid: "{{ vm_info.response.entities[0].metadata.uuid }}"
        name: testserver-efi
        boot_config:
          boot_type: UEFI

Without the boot_config options, it does clone the VM (ie. I am getting a valid vm uuid to clone).

Stack trace

TASK [Clone the VM] ***************************************************************************************************************************************************************
task path: /Users/chriswolske/code/nutanix/clone_efi_test.yml:23
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'boot_config'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible-chriswolske/ansible-tmp-1682611789.6303968-98346-190151390542911/AnsiballZ_ntnx_vms_clone.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/tmp/ansible-chriswolske/ansible-tmp-1682611789.6303968-98346-190151390542911/AnsiballZ_ntnx_vms_clone.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/tmp/ansible-chriswolske/ansible-tmp-1682611789.6303968-98346-190151390542911/AnsiballZ_ntnx_vms_clone.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_vms_clone', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_vms_clone', _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 \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms_clone.py\", line 342, in <module>\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms_clone.py\", line 338, in main\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms_clone.py\", line 332, in run_module\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms_clone.py\", line 291, in clone_vm\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py\", line 89, in get_clone_spec\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py\", line 226, in get_spec\n  File \"/var/folders/p7/59sg43s15sq699yzvx1tw9bm0000gp/T/ansible_ntnx_vms_clone_payload_q4k21hz_/ansible_ntnx_vms_clone_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py\", line 343, in _build_spec_boot_config\nKeyError: 'boot_config'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Expected behavior Nutanix should clone the VM and use EUFI to boot the clone (leaving the original intact). If switching boot options during cloning isn't possible, the option shouldn't be available as part of the vms_clone module. In any event, the module should handle the error and provide useful feedback.

Additional context For what it's worth, this "clone and switch boot methods" is a work-around to my initial problem -- I need a way to switch the boot priority (scsi.4 for example) and there seems to be no way to do it with either nutanix.ncp modules or the Prism API. There is an old acli command that will do it, but that is not practical for us because we are trying to execute this across hundreds of clusters.

bhati-pradeep commented 10 months ago

Added in release v1.9.1