Adding and formatting additional disks

Hi,

I’d like to get some community input on this scenario;

Using vmware.vmware.deploy_content_library_ovf you can deploy an imagebuilder image.

Adding an additional disk after the deployment is difficult using vmware.vmware.vm compared to community.vmware.vm_guest_disk because vmware.vmware is quite explicit instead of implicit.

The community module just adds an extra disk, whereas using vmware.vmware.vm requires you to figure out the list of disks before adding (and increasing the SCSI bus numbers) to the existing machine.

Does anyone have an example on how to do this while keeping the playbook modular and end up with a working machine?

The additional disk should be formatted using the redhat.rhel_system_roles.storage role (or the upstream linux system roles variant)

I dont have a concrete example, but I think using an _info module to get the current disks would be the answer. vmware.vmware.guest_info doesnt return this information, so maybe an opportunity for an enhancement

Thanks, that was my idea (using community.vmware.guest_info) as well but like I said, getting the formatting for SCSI right is critical here.

Will make an RFE later for the guest_info module to also return disk info (if not already present)

You can actually get this information using the vmware.vmware_rest repo. I still think something more elegant could be added in the guest_info module but you could do something like this:

---
- name: Test
  hosts: localhost
  gather_facts: no
  vars:
    dc: Eco-Datacenter
    vm_name: auto-xjv6-xcopy-template-test-storage-class--cold-y6t8

  tasks:
    - name: Test
      vmware.vmware_rest.vcenter_vm_info:
        vm: "{{ lookup('vmware.vmware.moid_from_path', '/' + dc + '/vm/' + vm_name) }}"
      register: _vm_info

    - name: Debug
      ansible.builtin.debug:
        var: _vm_info.value.disks

    - name: Parse disks
      ansible.builtin.set_fact:
        disks: >-
          {{ disks | default([]) + [
            "SCSI(" + (item.bus | string) + ":" + (item.unit | string) + ")"
          ] }}
      loop: "{{ _vm_info.value.disks.values() | selectattr('type', 'equalto', 'SCSI') | map(attribute='scsi') | list }}"

    - name: Debug
      ansible.builtin.debug:
        var: disks

The parse disks example you give is exactly what I would hope to avoid here. It seems so brittle, unnecessary complex to use in a role that I’m wondering if it should just be abstracted away into the module as an additional option similar to how microsoft.ad.group can “add”, “remove” or “set” the list of users.

Thats fair; I agree with your feelings about the extra steps in the playbook.

Part of the challenge with the disks (and vm devices in general) is that there needs to be a way to identify the device. For example, if you just provided a list of sizes its unclear what will happen if you remove any items in the list except the last one. Even if you had an option to just “append” the disk to the list, its unclear what the next run of the module would do since theres no identifier. Since VMWare doesnt give or communicate device IDs to the user, the best way to identify which disk your talking about is by specifying the bus and unit number.

The vm module does have a disks_remove_unmanaged option, which means you dont need to specify all the disks. That would make the parsing in your playbook a little simpler.