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

36 views
Skip to first unread message

Vincent Burgun

unread,
Feb 27, 2017, 12:48:07 PM2/27/17
to Ansible Project
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


GoFigure

unread,
Mar 21, 2018, 6:24:08 PM3/21/18
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages