Closed kengsia closed 6 months ago
ansible version :ansible [core 2.14.9] collection version: 3.11.2
@kengsia Message "Failed to find virtual machine find_vm_by_name
. This function used in many other modules this collection.
The problem is probably in the parameters you pass to the module.
/<datacenter name>/vm/
).hello @ihumster
Thanks for your feedback .
hello @ihumster It's wired I succesfuly use vmware.vmwarer_datacenter_info module to find out the datacenter "Singapore-Cloud" but it failed to find the folder "/Singapore-Cloud/vm"
output of playbook:
{ "name": "Singapore-Cloud", "moid": "datacenter-517", "config_status": "gray", "overall_status": "gray" },
{ "msg": "Failed to find folder specified by /Singapore-Cloud/vm", "invocation": { "module_args": { "hostname": "sgpvcs01.mycompany.com", "username": "admin\user1", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "vm_name": "sgpvm0001", "folder": "/Singapore-Cloud/vm", "validate_certs": false, "port": 443, "vm_type": "all", "show_attribute": false, "show_cluster": true, "show_datacenter": true, "show_datastore": true, "show_folder": true, "show_esxi_hostname": true, "show_mac_address": true, "show_net": true, ...
does it matter we have more than 4000 VMs in our vCenter ?
Oh. Folder <datacenter>/vm/
is special system folder. Please read carefully this page from vSphere API documentation. https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.ServiceInstance.html
And take a look at the picture. Asterisks point to 5 special system folders in vSphere Managed Objects Hierarchy (datacenterFolder, hostFolder, networkFolder, datastoreFolder and vmFolder). And get info about this folders I think not work.
You can also read information about the Folder
object.
https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.Folder.html
hello @ihumster , Actually my purpose is to develop a playbook to create snapshot for specific VM , the "vmware_guest_snapshot" module needs the folder path if the vm name provided . Then I have to use " vmware_guest_find" module to find out the folder of VM firstly . I also tried below playbook :
but when I run the playbook , it says ""Unable to manage snapshots for non-existing VM sgpvm0001" , it cannot find the VM which is apparently existing in the vCenter . I also tried to use moid instead of vm name but it still cannot find the VM .
Do you have any suggestions how I manage the snapshot for a specific VM ? Thanks.
@kengsia Open vSphere Client (vCenter UI) and take look on your tree VMs and Folders
. You mast view next hierarchy:
<vCenter Name or IP>
|-- <Datacenter Name>
| -- <VM Folder>
| |-- <VM in Folder>
| ...
|-- <VM in root>
|-- <VM in root>
The folder path is constructed as follows: /<Datacenter Name>/vm/<VM Folder>/<Next Nested VM Folder>/<VM Name>
For VMs in root he being short /<DC Name>/vm/<VM in root>
, for VM in some folder path will be longer.
hello @ihumster since we have multiple vCenters and datacenters which are managed by other team and they may adjust the hierarchy in future , so it will be better for us to use playbook to find the vm folder path automatically instead of inputting static value into playbook .
For example , below is one of our vCenter , we still have one hierarchy before datacenter . so the folder path will be "standard esxi servers/Datacenter_name/vm/" ?
Sorry I failed to attach the screenshot The hierarchy of my vCenter is like:
<vCenter Name or IP>
|--Folder1 (dedicated ESXi servers)
|-- Folder2 (standard ESXi servers)
|-- <Datacenter Name>
|-- <VM in root>
|-- <VM in root>
Then the folder path should be "Folder2/DC_name/vm/
@kengsia If Folder1/Folder2 is type of Datacenter Folder
then path is /Folder2/DC_Name/vm/
.
Hi @ihumster yes , Folder1/Folder2 is type of Datacenter Folder , but it still cannot find the specific VM , also not work when providing moid instead of vm name . curious what is the cause for this problem .
{ "msg": "Unable to manage snapshots for non-existing VM sgpvm0001", "invocation": { "module_args": { "datacenter": "Singapore-Cloud", "folder": "Standard ESXI Servers/Singapore-Cloud/vm", "hostname": "sgpvcs01.mycomany.com", "username": "admin\user1", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "name": "sgpvm0001", "state": "present", "snapshot_name": "test", "description": "test", "validate_certs": false, "port": 443, "name_match": "first", "use_instance_uuid": false, "quiesce": false, "memory_dump": false, "remove_children": false, "proxy_host": null, "proxy_port": null, "uuid": null, "moid": null, "snapshot_id": null, "new_snapshot_name": null, "new_description": null } }, "_ansible_no_log": null, "changed": false, "_ansible_delegated_vars": { "ansible_host": "localhost", "ansible_port": 22, "ansible_user": "root", "ansible_connection": "local" } }
@kengsia You can test work with API through PowerCLI? Use Get-VM cmdLet with your credentials and other used in playbook paramters.
hello @ihumster , I found the root cause , Ansible is case sensitive, all vms in our environment are in upper case. I updated my playbook "name: "{{ vm_short_name | upper }}"" Thanks for your support and suggestions.
SUMMARY
vm_info module cannot find specific vm
below is my playbook:
name: Set vm_name variable set_fact: vm_short_name: "{{ ansible_hostname }}"
debug: msg: "{{ vm_short_name }}"
name: Gather VM info community.vmware.vmware_vm_info: hostname: '{{ vcenter_hostname }}' username: '{{ vcenter_username }}' password: '{{ vcenter_password }}' vm_name: '{{ vm_short_name }}' validate_certs: false delegate_to: localhost register: vm_info
debug: var: "{{ vm_info.virtual_machines }}"
when I run it , I receive below error :
{ "msg": "Failed to find virtual machine sgpvm0001", "invocation": { "module_args": { "hostname": "sgpvcs01.mycompany.com", "username": "admin\user1", "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "vm_name": "sgpvm0001", "validate_certs": false, "port": 443, "vm_type": "all", "show_attribute": false, "show_cluster": true, "show_datacenter": true, "show_datastore": true, "show_folder": true, "show_esxi_hostname": true, "show_mac_address": true, "show_net": true, "show_resource_pool": true, "show_tag": false, "show_allocated": false, "proxy_host": null, "proxy_port": null, "folder": null } }, "_ansible_no_log": null, "changed": false, "_ansible_delegated_vars": { "ansible_host": "localhost", "ansible_port": 22, "ansible_user": "root", "ansible_connection": "local" } }
ISSUE TYPE
COMPONENT NAME
##### ANSIBLE VERSIONCOLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS