ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
344 stars 336 forks source link

vmware_guest fails when attempting to modify disks with unit or controller number of 0 #899

Closed APolts closed 3 years ago

APolts commented 3 years ago
SUMMARY

When using vmware_guest.py, supplying values of 0 for disk:controller_number and disk:unit_number causes the playbook to erroneously trip an if statement on line 2481, as values of 0 pass the conditional of (if not ).

ISSUE TYPE
COMPONENT NAME

vmware_guest

ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
CONFIGURATION
DEFAULT_GATHER_SUBSET(/etc/ansible/ansible.cfg) = ['all']
DEFAULT_GATHER_TIMEOUT(/etc/ansible/ansible.cfg) = 10
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = ['/etc/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/etc/ansible/ansible.cfg) = skippy
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

Ubuntu 20.04.1 LTS VSphere Client Version 6.7.0.46000

STEPS TO REPRODUCE

Supply values of 0 for disk.controller_number and disk.unit_number.

This error is reproducible both when hard-coding values for unit_number and disk_number and when fetching them with vmware.vmware_guest_disk_info.

      - name: Edit Disk Size
        environment: "{{ proxyenv }}"
        community.vmware.vmware_guest:
          hostname: "{{ vcenterHostname }}"
          username: "{{ vcenterUsername }}"
          password: "{{ vcenterPassword }}"
          name: "{{ vmName }}"
          disk:
            - size_gb: "{{ vmDiskNewSize }}"
              controller_type: "lsilogicsas"
              controller_number: 0
              unit_number: 0
              type: "thick"
          validate_certs: no
      - name: Gather info about the VM's Disks
        environment: "{{ proxyenv }}"
        community.vmware.vmware_guest_disk_info:
          hostname: "{{ vcenterHostname }}"
          username: "{{ vcenterUsername }}"
          password: "{{ vcenterPassword }}"
          datacenter: "{{ vmDatacenter }}"
          name: "{{ vmName }}"
          validate_certs: no
        register: vm_disk_info
      - name: Edit Disk Size
        environment: "{{ proxyenv }}"
        community.vmware.vmware_guest:
          hostname: "{{ vcenterHostname }}"
          username: "{{ vcenterUsername }}"
          password: "{{ vcenterPassword }}"
          name: "{{ vmName }}"
          disk:
            - size_gb: "{{ vmDiskNewSize }}"
              controller_type: "{{ vm_disk_info.guest_disk_info[vmDiskToModify].controller_type }}"
              controller_number: "{{ vm_disk_info.guest_disk_info[vmDiskToModify].controller_bus_number }}"
              unit_number: "{{ vmDiskToModify }}"
              type: "thick"
          validate_certs: no
EXPECTED RESULTS

Commenting out lines 2481 and 2482 results in the playbook performing without issue.

TASK [Edit Disk Size] **********************************************************
changed: [localhost] => {"changed": true, "instance": {"advanced_settings": {"disk.EnableUUID": "TRUE", "ethernet0.pciSlotNumber": "224", "hpet0.present": "TRUE", "ide0:0.autodetect": "TRUE", "migrate.hostLog": "20210607-test-04-41077afb.hlog", "migrate.hostLogState": "none", "migrate.migrationId": "7173189896302107267", "monitor.phys_bits_used": "43", "numa.autosize.cookie": "40001", "numa.autosize.vcpu.maxPerVirtualNode": "4", "nvram": "20210607-test-04.nvram", "pciBridge0.pciSlotNumber": "17", "pciBridge0.present": "TRUE", "pciBridge4.functions": "8", "pciBridge4.pciSlotNumber": "21", "pciBridge4.present": "TRUE", "pciBridge4.virtualDev": "pcieRootPort", "pciBridge5.functions": "8", "pciBridge5.pciSlotNumber": "22", "pciBridge5.present": "TRUE", "pciBridge5.virtualDev": "pcieRootPort", "pciBridge6.functions": "8", "pciBridge6.pciSlotNumber": "23", "pciBridge6.present": "TRUE", "pciBridge6.virtualDev": "pcieRootPort", "pciBridge7.functions": "8", "pciBridge7.pciSlotNumber": "24", "pciBridge7.present": "TRUE", "pciBridge7.virtualDev": "pcieRootPort", "sched.swap.derivedName": "/vmfs/volumes/5e4c2845-32be0376-8a92-e4434ba01b00/20210607-test-04/20210607-test-04-42db0f7d.vswp", "softPowerOff": "FALSE", "svga.guestBackedPrimaryAware": "TRUE", "svga.present": "TRUE", "tools.remindInstall": "FALSE", "vm.genid": "8368178417536056991", "vm.genidX": "-7583830971612183779", "vmci0.pciSlotNumber": "32", "vmotion.checkpointFBSize": "4194304", "vmotion.checkpointSVGAPrimarySize": "4194304", "vmware.tools.internalversion": "10341", "vmware.tools.requiredversion": "11265"}, "annotation": "", "current_snapshot": null, "customvalues": {}, "guest_consolidation_needed": false, "guest_question": null, "guest_tools_status": "guestToolsNotRunning", "guest_tools_version": "10341", "hw_cluster": "C365CRD", "hw_cores_per_socket": 1, "hw_datastores": ["C603GPQ_01"], "hw_esxi_host": "c736xpu.int.thomsonreuters.com", "hw_eth0": {"addresstype": "assigned", "ipaddresses": null, "label": "Network adapter 1", "macaddress": "00:50:56:9b:7c:28", "macaddress_dash": "00-50-56-9b-7c-28", "portgroup_key": "dvportgroup-5864", "portgroup_portkey": "1868", "summary": "DVSwitch: 50 1b 00 4a 9e d2 c4 50-02 09 a9 19 6c 40 7e 65"}, "hw_files": ["[C603GPQ_01] 20210607-test-04/20210607-test-04.vmx", "[C603GPQ_01] 20210607-test-04/20210607-test-04.vmxf", "[C603GPQ_01] 20210607-test-04/20210607-test-04.nvram", "[C603GPQ_01] 20210607-test-04/20210607-test-04.vmsd", "[C603GPQ_01] 20210607-test-04/vmware-9.log", "[C603GPQ_01] 20210607-test-04/vmware-8.log", "[C603GPQ_01] 20210607-test-04/vmware-7.log", "[C603GPQ_01] 20210607-test-04/vmware-6.log", "[C603GPQ_01] 20210607-test-04/vmware.log", "[C603GPQ_01] 20210607-test-04/vmware-11.log", "[C603GPQ_01] 20210607-test-04/vmware-10.log", "[C603GPQ_01] 20210607-test-04/20210607-test-04.vmdk", "[C603GPQ_01] 20210607-test-04/20210607-test-04_1.vmdk"], "hw_folder": "/Eagan-H-CIS/vm/Test", "hw_guest_full_name": "Microsoft Windows Server 2016 or later (64-bit)", "hw_guest_ha_state": null, "hw_guest_id": "windows9Server64Guest", "hw_interfaces": ["eth0"], "hw_is_template": false, "hw_memtotal_mb": 8192, "hw_name": "20210607-test-04", "hw_power_status": "poweredOff", "hw_processor_count": 4, "hw_product_uuid": "421b3822-3659-a69a-2228-a943eb8dc68d", "hw_version": "vmx-13", "instance_uuid": "501b7f86-2f10-0fa3-8d0a-b1e8521be336", "ipv4": null, "ipv6": null, "module_hw": true, "moid": "vm-7259", "snapshots": [], "vimref": "vim.VirtualMachine:vm-7259", "vnc": {}}}
ACTUAL RESULTS

The playbook errors out, telling the user that unit_number, controller_number and controller_type are required parameters.

TASK [Edit Disk Size] **********************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "'disk.controller_type', 'disk.controller_number' and 'disk.unit_number' are mandatory parameters when configure multiple disk controllers and disks."}

Ran in verbose mode:

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "advanced_settings": [],
            "annotation": null,
            "cdrom": [],
            "cluster": null,
            "convert": null,
            "customization": {
                "autologon": null,
                "autologoncount": null,
                "dns_servers": null,
                "dns_suffix": null,
                "domain": null,
                "domainadmin": null,
                "domainadminpassword": null,
                "existing_vm": null,
                "fullname": null,
                "hostname": null,
                "hwclockUTC": null,
                "joindomain": null,
                "joinworkgroup": null,
                "orgname": null,
                "password": null,
                "productid": null,
                "runonce": null,
                "timezone": null
            },
            "customization_spec": null,
            "customvalues": [],
            "datacenter": "ha-datacenter",
            "datastore": null,
            "delete_from_inventory": false,
            "disk": [
                {
                    "autoselect_datastore": null,
                    "controller_number": 0,
                    "controller_type": "lsilogicsas",
                    "datastore": null,
                    "disk_mode": null,
                    "filename": null,
                    "size": null,
                    "size_gb": 12,
                    "size_kb": null,
                    "size_mb": null,
                    "size_tb": null,
                    "type": "thick",
                    "unit_number": 0
                }
            ],
            "esxi_hostname": null,
            "folder": null,
            "force": false,
            "guest_id": null,
            "hardware": {
                "boot_firmware": null,
                "cpu_limit": null,
                "cpu_reservation": null,
                "hotadd_cpu": null,
                "hotadd_memory": null,
                "hotremove_cpu": null,
                "max_connections": null,
                "mem_limit": null,
                "mem_reservation": null,
                "memory_mb": null,
                "memory_reservation_lock": null,
                "nested_virt": null,
                "num_cpu_cores_per_socket": null,
                "num_cpus": null,
                "scsi": null,
                "version": null,
                "virt_based_security": null
            },
            "hostname": "10.252.41.18",
            "is_template": false,
            "linked_clone": false,
            "name": "20210607-test-04",
            "name_match": "first",
            "networks": [],
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": "10.252.33.216",
            "proxy_port": 80,
            "resource_pool": null,
            "snapshot_src": null,
            "state": "present",
            "state_change_timeout": 0,
            "template": null,
            "use_instance_uuid": false,
            "username": "administrator@ostvsphere.local",
            "uuid": null,
            "validate_certs": false,
            "vapp_properties": [],
            "wait_for_customization": false,
            "wait_for_customization_timeout": 3600,
            "wait_for_ip_address": false,
            "wait_for_ip_address_timeout": 300
        }
    },
    "msg": "'disk.controller_type', 'disk.controller_number' and 'disk.unit_number' are mandatoroy parameters when configure multiple disk controllers and disks."
}
mariolenz commented 3 years ago
ANSIBLE VERSION
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]

You're ansible version doesn't contain... the version of ansible you're using :-P

This looks a bit like a duplicate of #703 which should have been fixed with #705. Does the problem still exist with a current version of ansible / this collection?

APolts commented 3 years ago

My apologies - I was using version 2.10.8.

I updated to the most recent version of this collection and the bug is no longer present. Thank you!