[vsphere_guest] add a new vmdk disk with an automatic number

Hi,
We use ansible 2.1.0.0 for create VM on vmware vSphere 6.0.

Sometimes we need to add a disk
We use a role “srv_disk”

- name: “Configure extra disk”
delegate_to: localhost
ignore_errors: yes
vsphere_guest:
vcenter_hostname: “{{ vcenter_hostname }}”
username: “{{ vcenter_username }}”
password: “{{ vcenter_password }}”
guest: “{{ inventory_hostname }}”
vm_disk:
disk1:
disk2:
size_gb: “{{ disk_size_gb }}”
type: thick
datastore: “{{ datastore.stdout }}”
state: reconfigured

The problem is that we are forced to add a disk number. This is problematic when we have to recall the role to create a third disk.

Is it possible to use a variable to indicate the number of the disk?
The ideal solution would be to be able to detect the number of discs on the VM and to automatically increment the number of the disc to be added.

exemple :
guest: “{{ inventory_hostname }}”
vm_disk:
disk1:
disk{{ disk_number }}:
size_gb: “{{ disk_size_gb }}”
type: thick
datastore: “{{ datastore.stdout }}”

Thank for your help

Hi Vincent,

Did you ever find a solution? I have very much the same requirement, adding disks to cloud instances. In my case it would be more of a case of incrementing the device name eg /dev/sda , /dev/sdb , /dev/sdc , etc.

Thanks
Dan