ansible-collections / community.vmware

Ansible Collection for VMware
GNU General Public License v3.0
352 stars 336 forks source link

new state in vmware_host_datastore to differentiate between unmount and remove #2006

Open christian-naenny opened 9 months ago

christian-naenny commented 9 months ago
SUMMARY

If I use state: absent in the vmware_host_datastore module, the VMFS volume is removed! But I do not want to remove it, I only want to unmount the VMFS volume

I would like to do what I already did in PowerShell as $StorageSys.UnmountVmfsVolume($DS.ExtensionData.Info.vmfs.uuid);

In the function umount_datastore_host in vmware_host_datastore.py the code is: self.esxi.configManager.datastoreSystem.RemoveDatastore(ds)

but this is not an unmount, this is a remove! There is a difference between these two!

The code for an unmount should be something like this: self.esxi.configManager.datastoreSystem.UnmountVMFSVolume(ds)

ISSUE TYPE
COMPONENT NAME

community.vmware.vmware_host_datastore

ADDITIONAL INFORMATION

Later in the process, I need to mount the VMFS Volumes again, this does not work if I removed the Datastore using the current solution of the module.

- name: "Unmount datastores"
  community.vmware.vmware_host_datastore:
    datastore_name: "{{ $dsName }}"
    datastore_type: vmfs
    esxi_hostname: "{{ $esxHostName }}"
    vmfs_device_name: "naa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    vmfs_version: 6
    state: dismount   # or any other value other than absent
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
sathyapj commented 8 months ago

+1. I tried this module for 'Unmount' function. Realized this module will Remove the datastore. Fortunately, the datastore was empty with no vms. Otherwise, I will be in a trouble at work!!

sathyapj commented 8 months ago

Module shows 'absent' is unmount. But it's trying to remove the datastore.

ryanb74 commented 4 months ago

After some more search in the VMware API documentation, I found out that if we want to unmount the VMware datastore, we must actually not use HostDatastoreSystem instance as this class doesn't provide any unmounting method but rather use the HostStorageSystem class, that provides the UnmountVmfsVolume method.

I also don't understand why in this ansible module, for the mount part, the CreateVmfsDatastore method of the "HostDatastoreSystem" class is used, and why it doesn't use instead the MountVmfsVolume from the HostStorageSystem class.

@genegr @mariolenz I'm tagging both of you as I saw that you contributed to the commit where this was introduced : https://github.com/ansible-collections/community.vmware/commit/9f06033bd87611d2d97323ae26dc2eb16c4064bb

Do you remember why it was implemented like that ? I guess this is most likely a mistake as the commit message itself mentions in it's body "creating/deleting a vVols datastore in addition to VMFS and NFS datastores.", this code doesn't mount or unmount the datastores but rather creates or remove a datastore if I understand properly

I'm taking a look at this issue so any input is welcome, thanks