If you try and add a new NFS datastore on a host and come across the below error you need you need to remove a stale NFS datastore entry. This is caused if a NFS volume was not removed properly from the host and the entry still exists in the esx.conf file.
Error:Call “HostDatastoreSystem.CreateNasDatastore” for object “ha-datastoresystem” on ESXi “192.x.x.x” failed. Operation failed, diagnostics report: Unable to resolve hostname ‘hostname‘
First SSH onto the host and login. First run
esxcfg-nas -l
This will error at this point, you need to add a host entry for the hostname reported in the error. The host entry needs to be added to /ect/hosts and can point to any IP it doesnt have to resolve it. Do this by using vi. Enter
vi /etc/hosts
Use the arrow keys to navigate down to the last entry. At this point either use the ‘i’ key to enter insert mode and add the entry that way or if you scroll to the last entry and enter shift+o the cursor will start a new line. Enter
“192.x.x.x hostname”. To save and quit hit Esc then “:wq”.
Now enter esxcfg-nas -l again and this will now list the NFS entry for the hostname in the error. Make a note of the volume name that matches the hostname in the error. Enter
esxcli storage nfs remove -v volume_name
Once removed clean up the host file and now you can add NFS datastores again