Awx: How should I properly configure inventories that query VMWare vSphere for node information?

Created on 10 Oct 2017  ·  11Comments  ·  Source: ansible/awx

ISSUE TYPE

  • Documentation

Really, it's a support request... Feel free to point me elsewhere if there's a better place for this kind of post.

COMPONENT NAME

  • UI
SUMMARY


What I want to do is create an inventory of all vm's on my vSphere that start with "web-".

I've read http://docs.ansible.com/ansible-tower/latest/html/userguide/inventories.html#vmware-vcenter and spent several hours experimenting with both smart and regular inventories on my test instance of AWX.

I have been able to create a regular inventory and add a vmware source to it. That source then pulls in every single vm we have. I have not been able to make the vmware source filter out all but the "web-" vm's.

I've been able to create a smart inventory that looks that vmware regular inventory and filters out all but the hosts I want.

Is that how I am supposed to do it?

Information about my setup:

Docker version 17.09.0-ce, build afdb6d4
AWX from github, devel branch. Last commit: d02221702fd680cd38068ec49597a7b627228c04
Installed using the docker instructions.

Related questions:

  • What syntax can I use in the "INSTANCE FILTERS" box when configuring a vmware source?

    • Can I use "*" as a wildcard?

    • What keys can I filter on? (I did look at https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.ini and https://docs.vmware.com/en/VMware-vSphere/6.0/com.vmware.vsphere.vcenterhost.doc/GUID-2B6A1637-384D-4597-B453-B575F0ECD8A7.html but I wasn't able to figure out how to apply that information...)

  • In https://github.com/ansible/ansible/blob/13e89b17cc8ac3676837608270a88864ff4282cb/contrib/inventory/vmware_inventory.ini#L101 there's something about reducing the data looked up to speed up inventory refreshes. How do I translate that into the variables textarea when configuring my vmware source?
  • Same question as the last bullet for "skip_keys".

    ENVIRONMENT
  • AWX version: devel

  • AWX install method: docker on linux
  • Ansible version: 2.4.0.0
  • Operating System: Ubuntu 16.04
  • Web Browser: Firefox
ui

Most helpful comment

@jerrac ok, if you check the server variables when the host is imported you will see something like this...

runtime:
  powerstate: poweredOn
  paused: false
  featuremask: []
  snapshotinbackground: false
  onlinestandby: false
  cleanpoweroff: null
  featurerequirement: []
  question: null
  boottime: null
  maxmemoryusage: 4096
  offlinefeaturerequirement: []
  minrequiredevcmodekey: null
  toolsinstallermounted: false
  suspendinterval: 0
  dynamicproperty: []
  quiescedforkparent: null
  dynamictype: null
  memoryoverhead: null
  needsecondaryreason: null
  vflashcacheallocation: 0
  host:
    _moId: host-xxx
    name: vm-ware-xxx.xxx.xxxx
  maxcpuusage: 4798
  device: []
  suspendtime: null
  recordreplaystate: inactive
  consolidationneeded: false
  connectionstate: connected
  dasvmprotection: {}
  faulttolerancestate: notConfigured
  nummksconnections: 0
config:
  uuid: xxxx-xxxxx-xxxxx-xxxx
  alternateguestname: ''
  npivonnonrdmdisks: null
  instanceuuid: xxxx-xxxxx-xxxxx-xxxx
  cpuaffinity: null
  repconfig: null
  npivdesirednodewwns: null
  memoryhotaddenabled: false
  swapstorageobjectid: null
  hardware: {}
  vappconfig: null
  tools: {}
  migrateencryption: null
  guestfullname: Ubuntu Linux (64-bit)
  changeversion: '2017-10-29T18:16:19.866193Z'
  defaultpowerops: {}
  forkconfiginfo: {}
  cpuhotremoveenabled: false

You could figure out what do you want to get... for example:

config.alternateguestname == "whatever" or runtime.host.name == "some_physical_host"

The same you could play with groups:

{{ 'Kafka' if "kfk" in config.name else 'guest' this will create a group "Kafka" in your inventory and assigned to all guests with "kfk" as vm_name...

All 11 comments

This would probably be a good question for the mailing list or irc channel... it looks like we support host_filters as source vars:

https://github.com/ansible/awx/blob/devel/awx/main/tasks.py#L1722-L1726

We use the built-in ansible vmware inventory script you can see more information here:

https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.ini#L64-L71

Posted: https://groups.google.com/d/msg/ansible-project/7TmCsty2S-Y/99fAFaPZAAAJ
I did ask in the awx IRC channel. All I ever saw were people logging in and out.

The awx project has its own mailing list and they'll probably direct you to that one: https://groups.google.com/forum/#!forum/awx-project

As I said in my last comment we support host_filters as a source var... have you tried that?

Yes. That was one of the things I was asking about. Apparently I wasn't specific enough. What keys and values can you use with host_filters? I tried quite a few things...

There's an example in the vmware_inventory.py source script in the ansible
repo here:

https://github.com/ansible/ansible/blob/devel/contrib/inventory/vmware_inventory.py#L257

I'm not sure what other properties are acceptable there.

On Thu, Oct 12, 2017 at 10:25 PM, David Reagan notifications@github.com
wrote:

Yes. That was one of the things I was asking about. Apparently I wasn't
specific enough. What keys and values can you use with host_filters? I
tried quite a few things...


You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/ansible/awx/issues/386#issuecomment-336332419, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAFdyPV_1o0OI-0h9hKjwVAPR4VF-unrks5srsn9gaJpZM4PzLKL
.

So, that would be the documentation issue that led me to post here.

http://docs.ansible.com/ansible-tower/latest/html/userguide/inventories.html#vmware-vcenter is not clear on what parameters and values you can filter on.

  • Instance Filters: Rather than importing your entire VMWare inventory, filter the instances returned by the inventory script based on a variety of metadata. Hosts are imported if they match any of the filters entered here.

For more information on the filters that can be used here, refer to the Quick Filters Available for vSphere Objects documentation at VMware.

The VMWare page that is linked lists a bunch of stuff, but it is not clear how you would translate that information into the Instance Filter field. Do you need {{ }} around your filter? Can you use a wildcard? The list of quick filters is a simple bullet list, how do you translate that into whatever AWX needs to filter on?

Use the Source Variables field to override variables found in vmware.ini and used by the inventory update script. Enter variables using either JSON or YAML syntax. Use the radio button to toggle between the two. For a detailed description of these variables view vmware_inventory.ini in the Ansible GitHub repo.

host_filters: "{{ config.guestid == 'rhel7_64Guest' }}" is the example given in the screenshot of what you can put in the "Source Variables" box. Again, it is very unclear what keys and values you can use for host_filters. I've tried config.name == "web-*", config.name == "fullhostname", name == "fullhostname", etc.

And it's not easy to test. I have 200+ vm's on my vSphere. It takes several minutes to load them all into the inventory. And I haven't figured out if I need to delete nodes from the inventory manually, or if applying a new filter will do it automatically. So I've been deleting and recreating the inventory for every test...

Anyway, that's where I'm at with this right now.

Try:
host_filters: "{{ ('web-' in guest.hostname) }}"

This worked for me... {{ "HOST" in config.name }},{{ runtime.powerstate == "poweredOn" }}, but I'm getting an odd error when running a playbook using the inventory that is imported from VMWare. Take a look to my issue https://github.com/ansible/awx/issues/524 and let me know if you are getting the same error.

@ricalenil That worked for me. I placed the filter in the INSTANCE FILTERS field.

I did not get any error message.

How did you find out what key's to check? (config.name and runtime.powerstate)

@jerrac ok, if you check the server variables when the host is imported you will see something like this...

runtime:
  powerstate: poweredOn
  paused: false
  featuremask: []
  snapshotinbackground: false
  onlinestandby: false
  cleanpoweroff: null
  featurerequirement: []
  question: null
  boottime: null
  maxmemoryusage: 4096
  offlinefeaturerequirement: []
  minrequiredevcmodekey: null
  toolsinstallermounted: false
  suspendinterval: 0
  dynamicproperty: []
  quiescedforkparent: null
  dynamictype: null
  memoryoverhead: null
  needsecondaryreason: null
  vflashcacheallocation: 0
  host:
    _moId: host-xxx
    name: vm-ware-xxx.xxx.xxxx
  maxcpuusage: 4798
  device: []
  suspendtime: null
  recordreplaystate: inactive
  consolidationneeded: false
  connectionstate: connected
  dasvmprotection: {}
  faulttolerancestate: notConfigured
  nummksconnections: 0
config:
  uuid: xxxx-xxxxx-xxxxx-xxxx
  alternateguestname: ''
  npivonnonrdmdisks: null
  instanceuuid: xxxx-xxxxx-xxxxx-xxxx
  cpuaffinity: null
  repconfig: null
  npivdesirednodewwns: null
  memoryhotaddenabled: false
  swapstorageobjectid: null
  hardware: {}
  vappconfig: null
  tools: {}
  migrateencryption: null
  guestfullname: Ubuntu Linux (64-bit)
  changeversion: '2017-10-29T18:16:19.866193Z'
  defaultpowerops: {}
  forkconfiginfo: {}
  cpuhotremoveenabled: false

You could figure out what do you want to get... for example:

config.alternateguestname == "whatever" or runtime.host.name == "some_physical_host"

The same you could play with groups:

{{ 'Kafka' if "kfk" in config.name else 'guest' this will create a group "Kafka" in your inventory and assigned to all guests with "kfk" as vm_name...

Thanks! That helps. :)

Was this page helpful?
0 / 5 - 0 ratings