nutanix / nutanix.ansible

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

[Bug] Error when updating size_gb using the int filter in module ntnx_vms #400

Closed arnofear closed 10 months ago

arnofear commented 11 months ago

Describe the bug When updating the 'size_gb' value of a VM disk using the int filter, the Playbook fail. However, if we update the value of another attribute like 'memory_gb' (also of integer type), it works !

To Reproduce Steps to reproduce the behavior:

  1. ansible-playbook vm-update-disk.yml

  2. Playbook vm-update-disk.yml:

    ---
    - name: Update VM
    hosts: localhost
    gather_facts: false
    collections:
    - nutanix.ncp
    vars:
    default_disk_size_gb: 100
    
    module_defaults:
    group/nutanix.ncp.ntnx:
      nutanix_host: '1.2.3.4'
      nutanix_username: 'my_username'
      nutanix_password: 'my_password'
      validate_certs: false
    
    tasks:
    - debug:
      msg: "default_disk_size_gb={{ default_disk_size_gb }} type_debug={{ default_disk_size_gb | type_debug }}"
    
    - name: Set my_disk_size_gb
    set_fact:
      my_disk_size_gb: "{{ default_disk_size_gb + 100 }}"
    
    - debug:
      msg: "my_disk_size_gb={{ my_disk_size_gb }} type_debug={{ my_disk_size_gb | type_debug }}"
    
    - debug:
      msg: "my_disk_size_gb={{ my_disk_size_gb }} type_debug + int_filter={{ my_disk_size_gb | int | type_debug }}"
    
    - name: Update VM disk size
    nutanix.ncp.ntnx_vms:
      vm_uuid: 910745e1-a417-4e07-8094-618fbf3783a3
      disks:
        - type: "DISK"
          uuid: 6ef7edde-e951-4e8b-8e64-470a4d913c09
          size_gb: "{{ my_disk_size_gb | int }}"

Stack trace

PLAY [Update VM] ***************************************************************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************************************************************
ok: [localhost] => 
  msg: default_disk_size_gb=100 type_debug=int

TASK [Set my_disk_size_gb] *****************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *******************************************************************************************************************************************************************************************************************************
ok: [localhost] => 
  msg: my_disk_size_gb=200 type_debug=str

TASK [debug] *******************************************************************************************************************************************************************************************************************************
ok: [localhost] => 
  msg: my_disk_size_gb=200 type_debug + int_filter=int

TASK [Update VM disk size] *****************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: '>=' not supported between instances of 'str' and 'int'
fatal: [localhost]: FAILED! => changed=false 
  module_stderr: |-
    Traceback (most recent call last):
      File "/home/my-user/.ansible/tmp/ansible-tmp-1695631123.1564648-281844-166705858546536/AnsiballZ_ntnx_vms.py", line 107, in <module>
        _ansiballz_main()
      File "/home/my-user/.ansible/tmp/ansible-tmp-1695631123.1564648-281844-166705858546536/AnsiballZ_ntnx_vms.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/home/my-user/.ansible/tmp/ansible-tmp-1695631123.1564648-281844-166705858546536/AnsiballZ_ntnx_vms.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.nutanix.ncp.plugins.modules.ntnx_vms', init_globals=dict(_module_fqn='ansible_collections.nutanix.ncp.plugins.modules.ntnx_vms', _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_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms.py", line 1003, in <module>
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms.py", line 999, in main
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms.py", line 991, in run_module
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/modules/ntnx_vms.py", line 862, in update_vm
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/entity.py", line 226, in get_spec
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py", line 335, in _build_spec_disks
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py", line 496, in _update_disk
      File "/tmp/ansible_nutanix.ncp.ntnx_vms_payload___pe35ll/ansible_nutanix.ncp.ntnx_vms_payload.zip/ansible_collections/nutanix/ncp/plugins/module_utils/prism/vms.py", line 431, in _generate_disk_spec
    TypeError: '>=' not supported between instances of 'str' and 'int'
  module_stdout: ''
  msg: |-
    MODULE FAILURE
    See stdout/stderr for the exact error
  rc: 1

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Expected behavior Success playbook when updating the 'size_gb' value of a VM disk using the int filter.

Additional context

Nutanix Version pc.2022.6.0.5 NCC Version: 4.6.3.1 LCM Version: 2.6.2

Debian 12 pipx installation ansible community version 8.4.0 ansible-core 2.15.4

collection nutanix.ncp version 1.8.0 (tested with version 1.9.0 too)

ansible-doc nutanix.ncp.ntnx_vms

...
- disks
...
        - size_gb
            The Disk Size in GB.
            This option is applicable for only DISK type above.
            default: null
            type: int
...
- memory_gb
        Memory size in GB
        default: null
        type: int

Thanks

bhati-pradeep commented 11 months ago

@Gevorg-Khachatryan-97 Please check this

bhati-pradeep commented 10 months ago

Fixed in release v1.9.1