# \[vsphere\_guest\] add a new vmdk disk with an automatic number

**URL:** <https://forum.ansible.com/t/vsphere-guest-add-a-new-vmdk-disk-with-an-automatic-number/23831>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [February 27, 2017, 5:36pm UTC](https://forum.ansible.com/t/vsphere-guest-add-a-new-vmdk-disk-with-an-automatic-number/23831 "2017-02-27T17:36:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vincent\_Burgun](https://avatars.discourse-cdn.com/v4/letter/v/bc8723/32.png) [@Vincent\_Burgun](https://forum.ansible.com/u/Vincent_Burgun)\
**Post date:** [February 27, 2017, 5:36pm UTC](https://forum.ansible.com/t/vsphere-guest-add-a-new-vmdk-disk-with-an-automatic-number/23831/1 "2017-02-27T17:36:50Z")

</div>

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_

---

<div class="post-metadata">

**Author:** ![GoFigure](https://avatars.discourse-cdn.com/v4/letter/g/a587f6/32.png) [@GoFigure](https://forum.ansible.com/u/GoFigure)\
**Post date:** [March 21, 2018, 10:24pm UTC](https://forum.ansible.com/t/vsphere-guest-add-a-new-vmdk-disk-with-an-automatic-number/23831/2 "2018-03-21T22:24:08Z")

</div>

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
