I need to get the VMID field from the column data as below.
[[root@prmh-mag-31:~] vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
51 myvgpu_clone2 [EVC_Store1] myvgpu_clone2/myvgpu_clone2.vmx windows8_64Guest vmx-11
so as above is the command result , i need to get the VMID corresponding to vm name myvgpu_clone2. For that i have used ansible command module and grepping the first output of vm list for vmname so i get the one row . now i have to get the VMID field from the single row.
I have used following code but it does not give the desired output. any help is aprreciated.
Thanks,
VM
name: Get the VM id of the powered ON VM
command: vim-cmd vmsvc/getallvms | grep ‘{{guest_name}}’ | “‘cut -d ’ ’ -f 1’”
register: ouputvmid
ignore_errors: true
I need to get the VMID field from the column data as below.
[[root@prmh-mag-31:~] vim-cmd vmsvc/getallvms
Vmid Name File
Guest OS Version Annotation
51 myvgpu_clone2 [EVC_Store1] myvgpu_clone2/myvgpu_clone2.vmx
windows8_64Guest vmx-11
so as above is the command result , i need to get the VMID corresponding
to vm name myvgpu_clone2. For that i have used ansible command module and
grepping the first output of vm list for vmname so i get the one row . now
i have to get the VMID field from the single row.
I have used following code but it does not give the desired output. any
help is aprreciated.
What output do you get and what's wrong with it?
name: Get the VM id of the powered ON VM
command: vim-cmd vmsvc/getallvms | grep '{{guest_name}}' | "'cut -d
' ' -f 1'"
register: ouputvmid
ignore_errors: true
Not all esx have python so you might need to use the raw module.
You need to remove the single and double quotes around cut like so.
- name: Get the VM id of the powered ON VM
command: vim-cmd vmsvc/getallvms | grep '{{guest_name}}' | cut -d' ' -f1
register: ouputvmid
Awesome Kai & Jean ! it worked when i used the shell command.
Lot of thanks to you guys!
ASK [ESX_VM_SnapRestore : Get the VM id of the powered ON VM] *********************************************************************************************************************************************
changed: