ansible-collections / community.vmware

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

Disk resize fails when using Ansible 2.15 #2043

Open kbreit opened 7 months ago

kbreit commented 7 months ago
SUMMARY

community.vmware is used to build Windows VMs in vSphere. The playbook has existed for a while and used to work but when using it in an Ansible 2.15 execution environment, it fails. It seems to work under 2.9 though. The error is:

"Failed to manage disks for virtual machine 'vm_test' with exception : (\"Parameters for device 'scsi0' may not be modified while the virtual machine is powered on.\", None)",

This error is coming from VMware as it shows in the vSphere web UI. However, resizing the disks in the web UI works, as does Ansible 2.9.

ISSUE TYPE
COMPONENT NAME

vmware_guest_disk

ANSIBLE VERSION
ansible [core 2.15.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, Sep 22 2023, 17:57:55) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)] (/usr/bin/python3.9)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection            Version
--------------------- -------
ansible.posix         1.5.2
ansible.windows       1.13.0
cloud.common          2.1.3
community.general     5.2.0
community.vmware      3.5.0
community.windows     1.12.0
infoblox.nios_modules 1.4.1
vmware.vmware_rest    2.3.1
CONFIGURATION
CONFIG_FILE() = /etc/ansible/ansible.cfg
OS / ENVIRONMENT

vsphere 7.0, Windows VM

STEPS TO REPRODUCE
#######
# Play: Add disk from disk_personalities
#
#   Applies when Virtual_System_Operation == "Deploy" and sequentially
#   after vSphere deployment actions have completed with success for the
#   guest system.
#######
    - name: Diskpersonality Deploy
      vmware_guest_disk:
        validate_certs: false
        hostname: "{{ selected_vcenter }}"
        username: "{{ vcenter.username }}"
        password: "{{ vcenter.password }}"
        datacenter: "{{ selected_vcenter_datacenter }}"
        folder: "{{ selected_vcenter_folder }}"
        name: "{{ guest_input_name }}"
        disk:
          - size_gb: "{{ item.sizegb|int }}"
            type: thin
            datastore: "{{ selected_vmguest_datastore }}"
            state: present
            disk_mode: "persistent"
            scsi_type: lsilogic
            scsi_controller: "{{ item.controller|int }}"
            unit_number: "{{ item.unit|int }}"
      delegate_to: localhost
      loop: "{{ disks }}"
      when:
        - Virtual_System_Operation == "Deploy"
        # - vestal_run == true
EXPECTED RESULTS

I would expect the play to resize the disks in vSphere.

ACTUAL RESULTS
  File "<string>", line 3, in raise_from
failed: [localhost] (item={'controller': '0', 'scsi_type': 'paravirtual', 'unit': '2', 'sizegb': '60', 'mountpoint': 'e', 'os_disknum': '2'}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "datacenter": "DC",
            "disk": [
                {
                    "autoselect_datastore": null,
                    "bus_sharing": "noSharing",
                    "cluster_disk": false,
                    "compatibility_mode": null,
                    "controller_number": null,
                    "controller_type": null,
                    "datastore": "vsanDatastore",
                    "destroy": true,
                    "disk_mode": "persistent",
                    "filename": null,
                    "iolimit": null,
                    "rdm_path": null,
                    "scsi_controller": 0,
                    "scsi_type": "lsilogic",
                    "shares": null,
                    "sharing": false,
                    "size": null,
                    "size_gb": 60,
                    "size_kb": null,
                    "size_mb": null,
                    "size_tb": null,
                    "state": "present",
                    "type": "thin",
                    "unit_number": 2
                }
            ],
            "folder": "Discovered virtual machine",
            "hostname": "vsphere.company.com",
            "moid": null,
            "name": "vm_test",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "port": 443,
            "proxy_host": null,
            "proxy_port": null,
            "use_instance_uuid": false,
            "username": "company\\\\username",
            "uuid": null,
            "validate_certs": false
        }
    },
    "item": {
        "controller": "0",
        "mountpoint": "e",
        "os_disknum": "2",
        "scsi_type": "paravirtual",
        "sizegb": "60",
        "unit": "2"
    },
    "msg": "Failed to manage disks for virtual machine 'vm_test' with exception : (\\"Parameters for device 'scsi0' may not be modified while the virtual machine is powered on.\\", None)"
mariolenz commented 7 months ago

It looks like you're using community.vmware 3.5.0 but this is quite old. Do you run into the same issue with 3.11.2 / 4.2.0 3.11.3 / 4.3.0?

kbreit-insight commented 6 months ago

@mariolenz Sorry about the delay but 4.3.0 doesn't appear to fix it.

SwiperNo commented 6 months ago

Having this same issue as well. I noticed that people were stating they fixed their issue by adding scsi_type, but seems like it still does not work on my end either. It looks like they were using community version 2.8 instead. I may revert back to this.

kbreit-insight commented 3 months ago

@SwiperNo Have you been able to come up with a fix for it on modern Ansible versions?

SwiperNo commented 3 months ago

@SwiperNo Have you been able to come up with a fix for it on modern Ansible versions?

I've worked with the bug for awhile, but I have not tried on 2.17. I thought since this issues was open and everyone hates Broadcom, I thought it would never be resolved. I'll research in the morning and update this week.

kbreit-insight commented 3 months ago

@SwiperNo How have you worked with it? Besides using an old Ansible version, we haven't been able to get it to work.

SwiperNo commented 3 months ago

@SwiperNo How have you worked with it? Besides using an old Ansible version, we haven't been able to get it to work.

I have converted our templates to paravirtual for now so the default option does not fail due to this bug. Another option is to manually fix the bug in your collections path.

kbreit-insight commented 2 months ago

@SwiperNo How would you fix this one in the code in the collection path? I haven't found anything in the code which (at least to me) would cause this problem.