# Managing VMDKs with Ansible

**URL:** <https://forum.ansible.com/t/managing-vmdks-with-ansible/4486>\
**Category:** Get Help\
**Tags:** vmware, collections\
**Created:** [March 20, 2024, 4:59pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486 "2024-03-20T16:59:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cweiss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cweiss/32/2564_2.png) [@cweiss](https://forum.ansible.com/u/cweiss)\
**Post date:** [March 20, 2024, 4:59pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/1 "2024-03-20T16:59:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [March 20, 2024, 5:35pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/2 "2024-03-20T17:35:08Z")

</div>

“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)](https://cormachogan.com/2018/11/21/a-primer-on-first-class-disks-improved-virtual-disks/) have been introduced. There’s a [module](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_first_class_disk_module.html) to create them since `community.vmware` version 1.7.0. But AFAIR we’ve never implemented attaching them to a VM somehow.

---

<div class="post-metadata">

**Author:** ![cweiss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cweiss/32/2564_2.png) [@cweiss](https://forum.ansible.com/u/cweiss)\
**Post date:** [March 20, 2024, 5:52pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/3 "2024-03-20T17:52:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [March 20, 2024, 6:31pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/4 "2024-03-20T18:31:07Z")

</div>

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](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_guest_disk_module.html) 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.

---

<div class="post-metadata">

**Author:** ![cweiss](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/cweiss/32/2564_2.png) [@cweiss](https://forum.ansible.com/u/cweiss)\
**Post date:** [March 27, 2024, 5:38pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/5 "2024-03-27T17:38:08Z")

</div>

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 🙂 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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [April 26, 2024, 5:38pm UTC](https://forum.ansible.com/t/managing-vmdks-with-ansible/4486/6 "2024-04-26T17:38:37Z")

</div>

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