vmware.vmware_rest icon indicating copy to clipboard operation
vmware.vmware_rest copied to clipboard

the lookups mis a usefull working example

Open RobVerduijn opened this issue 2 years ago • 2 comments

Hello,

I've been reading through all the new features of the vmware.wmware_rest collection and was pleasantly surprised to see that lookups have been added.

And really dissapointed after reading the docs.

Now they are easy enough to use in a static environment. However when you have a more dynamic environment they are rather useless. ie: a hardcoded search path is nice for a static environment.

- name: lookup MoID of the object
  debug: msg="{{ lookup('vmware.vmware_rest.vm_moid', '/my_dc/host/my_cluster/esxi1.test/test_vm1', **connection_args) }}"

you need to find the path only once and you are done with it

can't you make it simply work with:

- name: lookup MoID of the object
  debug: msg="{{ lookup('vmware.vmware_rest.vm_moid', 'test_vm1', **connection_args) }}"

and while you are at it, make it respect environment args ?

- name: myplay
  environment:
     VMWARE_HOST: my_host
     VMWARE_USER: my_user
    etc etc
  tasks:
     - name: lookup MoID of the object
       debug: msg="{{ lookup('vmware.vmware_rest.vm_moid', 'test_vm1') }}"

and if all that already works, make this a bit more obvious in the docs

Rob

SUMMARY
ISSUE TYPE
  • Documentation Report
COMPONENT NAME
ANSIBLE VERSION

RobVerduijn avatar Sep 15 '21 13:09 RobVerduijn

@RobVerduijn Thank you for raising this. The vmware inventory has a hierarchical structure. The main limitation the moment is that the information about such hierarchy is totally absent from the API responses. If we'd only consider the name of the object, in the case of multiple objects of the same type and with the same name in different paths, the search query would return all of them. The filter plugins avoid this by checking the entire object path and returning the exact object the used wanted to use.

alinabuzachis avatar Sep 22 '21 09:09 alinabuzachis

Yes, thank you for explaining the filter plugin.

So in a dynamic environment in a play which does NOT assume any knowledge about the path you still need to do many tasks with other modules to determine the path.

This filter does not reduce the amount of ansible code, why would I use this filter ?

Rob

RobVerduijn avatar Sep 30 '21 09:09 RobVerduijn