Managing VMDKs with Ansible

I am trying to create a VM with an add-on disk that I can preserve between creation/destruction of the core VM.
It seems like there’s no real facilities in the community.vmware collection to move or even create a VMDK (without it being created attached to a VM).

I assume I could do the work with custom scripts that call the API, but it sure seems like this functionality would be a part of the core collection. Is there a particular reason there’s no “move” or “new unattached VMDK” function? How are other people dealing with managing VMDKs?

“Normal” VMDKs don’t exist outside of of VM, at least I don’t know any way to create one without it being a part of a VM via the API.

That’s why First Class Disk (FCD) have been introduced. There’s a module to create them since community.vmware version 1.7.0. But AFAIR we’ve never implemented attaching them to a VM somehow.

1 Like

Ahh, that’s unfortunate. I’m newish to the VMWare ecosystem. The ability for Ansible to attach an existing VMDK from another folder to a VM inspired me to try this path.

We were using FCDs, but something recently broke functionality on our system and I’m pretty sure it’s our problem, not Ansible/community.vmware/Python.

Thanks for the reply!

If you want to remove an existing disk from a VM and attach it to another one, maybe you could use vmware_guest_disk_module with disk.state=absent and destroy=false. This should remove the virtual disk from the the VM without deleting it.

And then you should be able to add the disk to another VM using the same module and setting disk.filename.

Not 100% sure, but I think it would be worth for you to have a look at this.

2 Likes

That pretty much works. The issue now is I have the original folder in the datastore called VM_Name with just the VMDK file in it, but when I go to create a new VM with the same name, it creates a new folder VM_Name_1 rather than using the existing one. I assume this is for my own protection :slight_smile: but I do wish there was a way to force it to create the VM in an existing non-empty folder.

This is now more an aesthetic issue than anything else. Detaching the VMDK (in the original folder) and destroying the VM will completely remove the VM_Name_1 folder, so I only ever end up with a single ‘extra’ folder if I re-create the VM.

Thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.