Finding a VM on VCenters

19 views
Skip to first unread message

Carter, Stephen

unread,
Aug 22, 2018, 12:03:17 PM8/22/18
to ansible...@googlegroups.com

Hello,

 

I was curious if anyone has come up with a decent way of accomplishing this.

 

I have an inventory file with a bunch of VM’s I manage currently.

 

When we do maintenances we like to take a snapshot just before we perform actions however, I am hitting a hitch of trying to find a way to determine what vCenter the VM is located on. There can be several it could be on, and I really don’t want to statically go and define it for all my VM’s.

 

Any ideas on the best way to accomplish this? I was thinking I could try vmware_guest_find and iterating through the vCenters but that seems inelegant and sort of slow.

 

Thanks

 

Arden Shackelford

unread,
Aug 22, 2018, 2:28:49 PM8/22/18
to Ansible Project
I'm not very familiar with vmware, but I'd ask around and see if you have access to the vmware API and see if there is an endpoint on which you could send a query for the current host.
I'd assume that the information provided about the host includes which vcenter the vm is on.

I've done something like this with GitHub releases.

Example: (Just Tested)

- name: Get Latest Release Number for App
  hosts: localhost

  tasks:
    - name: Get Release Number
      uri:
        method: GET
        return_content: yes
        body_format: json
      register: latest_release

    - debug:
        var: latest_release.json.tag_name


You'll see if you run that the output shows the tag_name object.

I'd bet you could do something similar to get what you need to put the vcenter into a variable so long as this can be pulled from the vmware API.

Izzy

unread,
Aug 22, 2018, 2:36:29 PM8/22/18
to ansible...@googlegroups.com
Not sure how you're Vcenters are setup, but in my environment our Vm's are not really assigned to specific Vcenter's so I use the UUID's to perform snapshots for each VM in one playbook.  I haven't figured out how to call the UUID so I have it set manually.

Israel



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6C256995-7C99-4FBD-A7B3-1D843397F49D%40contoso.com.
For more options, visit https://groups.google.com/d/optout.

Carter, Stephen

unread,
Aug 22, 2018, 3:37:33 PM8/22/18
to ansible...@googlegroups.com

All of our vCenters are unlinked, and completely independent making it a little more difficult.

 

It’s possible we could have some more luck using a dynamic inventory from vCenter. We are looking at Tower, so it could be a possibility.

Jonathan Lozada De La Matta

unread,
Aug 22, 2018, 4:23:25 PM8/22/18
to ansible...@googlegroups.com
you might try https://docs.ansible.com/ansible/2.6/modules/vmware_vm_facts_module.html and see what you get back. I don't have an area to test it though.


For more options, visit https://groups.google.com/d/optout.


--

Jonathan lozada de la matta

AUTOMATION CONSULTANT - AUTOMATION PRACTICE

Red Hat Consulting Services

jloz...@redhat.com   



 

Reply all
Reply to author
Forward
0 new messages