Hi Doug O'Leary,

I came up with this -

  tasks:
  - name: Get all disks in all controllers
    vmware_guest_disk_info:
      validate_certs: False
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_username }}'
      password: '{{ vcenter_password }}'
      datacenter: Asia-Datacenter1
      name: VM_8046
    register: existing_disk

  - name: Create a dict with controller and the total number of disks
    set_fact:
      disk_info: "{{ disk_info | default({}) | combine({
item.value.controller_bus_number : item.value.unit_number} )}}"
    with_dict: "{{ existing_disk.guest_disk_info }}"

  - debug:
      msg: "{{ disk_info }}"


Here, I am iterating over all disks and controllers in the given VM. I get
a final count of all disks available on each controller in disk_info
dictionary. Once I have that information I can figure out what is next disk
in the given controller.

Also, you can take a look at this example to add more disk using
vmware_guest_disk -
https://github.com/Akasurde/ansible-reproducers/blob/master/55999/i55999.yml

Let me know if you need any help on this.

Thanks,
Abhijeet Kasurde

On Tue, Dec 10, 2019 at 7:29 PM Doug OLeary <[email protected]>
wrote:

> Hi;
>
> I'm trying to automate the addition of disk devices to VM guests.  After a
> bit of work and lots of lessons learned, I've gotten to this point:
>
>   - name: add disk space
>     vmware_guest_disk:
>       hostname: "{{s}}"
>       username: "{{vu}}"
>       password: "{{vp}}"
>       datacenter: "{{dc}}"
>       validate_certs: no
>       name: "{{inventory_hostname}}"
>       disk:
>         - size_gb: 20
>           type: thick
>           datastore: "{{dsi.datastores[0].datastore_cluster}}"
>           scsi_controller: 0
>           state: present
>     delegate_to: localhost
>     when:
>       - dsi.datastores[0].datastore_cluster|length > 0
>       - dsi.datastores[0].freeSpace / dsi.datastores[0].capacity * 100 >
> 20
>
> This results in:
>
> TASK [add disk space]
> ***************************************************************************************************
> fatal: [cl1vinfspt1000 -> localhost]: FAILED! => {"changed": false, "msg": 
> "Please
> specify 'unit_number' under disk parameter
> at index [0], which is required while creating disk."}
>
> The number of disks on the vms which need disk additions is going to vary
> - in fact, some may even have multiple controllers.  I've used govc to add
> disks to vms and it just tacks the disk on the end of the bus.
>
> So, two questions:
>
>
>    - Is there a way to tell vmware_guest_disk to use the next available
>    unit number?
>    - Failing that, is there a clever way to identify the next available
>    scsi unit number?  I'm even willing to use OS commands and create a
>    variable... interesting thought, that.  I'll look there next.
>
>
> Thanks for any hints/tips/suggestions.
>
> Doug O'Leary
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a04b73d3-c17c-4cf8-a632-8b610d171cf8%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a04b73d3-c17c-4cf8-a632-8b610d171cf8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Thanks,
Abhijeet Kasurde

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFwWkHoXzyJax0fPcecEiULoF0E0Qc7azv1WuWd0R8bp-i_bzw%40mail.gmail.com.

Reply via email to