Ansible- add disk to vm skipping SCSI ID (x:7)

As the virtual SCSI adapter requires a SCSI ID and No 7 is reserved for it, let’s try to handle it writing Ansible’s task.

We will use ‘vmware_guest_disk‘ module to add disk to vm. Because two disk parameters are required: ‘scsi_controler’ and ‘unit_number’, we will try to use Jinja2 filter ‘|int + 1’ to add next available SCSI device Unit Number.

1. First we need to use ‘vmware_guest_disk_facts‘ module to gather disk facts from our vm where we want to add new vdisk:

2. Task to list currently used SCSI Controller Bus Number (controller_key):

3. Next step is to sort ‘controller_key‘ by last number in use.

4. Set fact for SCSI device Unit Number (unitNumber) – pay attention at ‘int + 1’ at the end of 3rd line:

5. And the most important step – skipping controller SCSI ID No 7. Otherwise you will get an error when add vdisk No 8.

6. So when we have a ‘controllerKey‘ and ‘unitNumber‘ defined we can just use both in ‘vmware_guest_disk‘ module to add new disk to our vm:

And that’s it.

Next part will cover creation of Windows partition on disk.