ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
348 stars 334 forks source link

Disk not resized when vmware vm scsi controller is "lsi logic" and vm is powered on #1595

Open PisikeSipelgas opened 1 year ago

PisikeSipelgas commented 1 year ago
SUMMARY

Disk not resized when vmware vm scsi controller is "lsi logic" and vm is powered on

ISSUE TYPE
COMPONENT NAME

vmware_guest_disk

ANSIBLE VERSION
  config file = /home/ps/.ansible.cfg
  configured module search path = ['/home/ps/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/ps/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.14 (main, Nov  7 2022, 00:00:00) [GCC 11.3.1 20220421 (Red Hat 11.3.1-2)]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION

Partial list:


# /usr/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
community.vmware              2.8.0

vmware.vmware_rest            2.2.0
CONFIGURATION
DEFAULT_ROLES_PATH(/home/ps/.ansible.cfg) = ['/etc/ansible/roles', '/usr/share/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/home/ps/.ansible.cfg) = skippy
DEFAULT_VAULT_PASSWORD_FILE(env: ANSIBLE_VAULT_PASSWORD_FILE) = /home/ps/.vault_pass
TRANSFORM_INVALID_GROUP_CHARS(env: ANSIBLE_TRANSFORM_INVALID_GROUP_CHARS) = ignore
OS / ENVIRONMENT

Rocky 9.1

STEPS TO REPRODUCE

VM is deployed from template where SCSI controller is set to "LSI Logic". Deployment is successful. Vmware tools are pre-installed. VM gets powered ON. Next step is to modify additional disk, which fails (see below). At the same time resizing disk disk directly from VmWare Vsphere Web console resizing works as expected (disk is resized without any problems). Solution is to change SCSI controller to be "VmWare Paravirtual". Without any change in playbooks everything works.

- name: add or resize hdd
  vmware_guest_disk:
    hostname: "{{ vmware_hostname }}"
    username: "{{ vmware_username }}"
    password: "{{ vmware_password }}"
    datacenter: "{{ vm_datacenter }}"
    name: "{{ vm_hostname }}"
    folder: "{{ vm_folder }}"
    disk:
      - size_gb: "{{ item.size|int }}"
        type: "thin"
        state: present
        scsi_controller: "{{ item.controller|int }}"
        unit_number: "{{ item.lun|int }}"
        disk_mode: persistent
        datastore: "{{ item.disk_datastore }}"
  loop: "{{ disks }}"
  delegate_to: localhost
  when: ( disks is defined )

where "disks" are defined in external json file like this:

    "disks": [
        {
            "mountpoint": "/data",
            "controller": 0,
            "lun": 1,
            "size": 75,
            "disk_datastore": "3PAR_comp"
        }
    ],
EXPECTED RESULTS

VM disk attached to "LSI Logic" will be resized regardless vm is powered "on" or "off". It did work with older ansible (centos 7 & ansible 2.9).

ACTUAL RESULTS

Task fails with message: "Parameters for device 'scsi0' may not be modified while the virtual machine is powered on."

(failed: [localhost] (item={'mountpoint': '/mnt', 'controller': 0, 'lun': 1, 'size': 200, 'disk_datastore': '3PAR_comp'}) => {"ansible_loop_var": "item", "changed": false, "item": {"controller": 0, "disk_datastore": "3PAR_comp", "lun": 1, "mountpoint": "/mnt", "size": 200}, "msg": "Failed to manage disks for virtual machine 'vm.example.com' with exception : (\"Parameters for device 'scsi0' may not be modified while the virtual machine is powered on.\", None)"})
mariolenz commented 1 year ago

I don't think this is really a problem with resizing, I think it's something else. Could you please add scsi_type: lsilogic to your disk and try again?

PisikeSipelgas commented 1 year ago

That did the trick!

    disk:
      - size_gb: "{{ item.size|int }}"
        type: "thin"
        state: present
        scsi_type: lsilogic
        scsi_controller: "{{ item.controller|int }}"
        unit_number: "{{ item.lun|int }}"
        disk_mode: persistent
        datastore: "{{ item.disk_datastore }}"
TASK [vm-modify : add or resize hdd] ************************
changed: [localhost] => (item={'mountpoint': '/data', 'controller': 0, 'lun': 1, 'size': 75, 'disk_datastore': '3PAR_comp'})
mariolenz commented 1 year ago

It looks like the module tries to change the type to paravirtual when neither scsi_type nor controller_type are set:

https://github.com/ansible-collections/community.vmware/blob/de8e030efcae4c19bd6b3e6670cdbc81b8656afc/plugins/modules/vmware_guest_disk.py#L863-L872

This is a bit... well, unexpected. I think the module shouldn't try to change the type to paravirtual when neither scsi_type nor controller_type are set. At least not on existing disks, I think it's OK for new ones.

I'm not sure yet what I should do about this. But at least you have a workaround now.

SwiperNo commented 4 months ago

That did the trick!

    disk:
      - size_gb: "{{ item.size|int }}"
        type: "thin"
        state: present
        scsi_type: lsilogic
        scsi_controller: "{{ item.controller|int }}"
        unit_number: "{{ item.lun|int }}"
        disk_mode: persistent
        datastore: "{{ item.disk_datastore }}"
TASK [vm-modify : add or resize hdd] ************************
changed: [localhost] => (item={'mountpoint': '/data', 'controller': 0, 'lun': 1, 'size': 75, 'disk_datastore': '3PAR_comp'})

Interesting I added scsi_type: lsilogic and still get the same issue.