Looking forward to this patch!
For those testing vmware, i’ve added a few features to vmware.py dynamic inventory which ec2.py inventory comes with but were sorely missing in vmware.py.
instance_filters and --refresh-cache. Plus a bug fix that allows cache_dir to be found.
https://github.com/ansible/ansible/pull/14136
If anyone is interested, i also added some hacky tag support by parsing the guest name and searching for specific tags that can be set in vmware.ini
Then guests with correct names will be put into ansible groups that can be mapped to roles in a vmware_hosts file.
I will make a separate PR for this if folks are interested, but it’s sort of a hack until vsphere_guest supports tags. Right now it suggests that it has ‘notes’ but none showed up for me.
def _get_vm_info(self, vm, prefix=‘vmware’):
‘’’
Return a flattened dict with info about the given virtual machine.
‘’’
vm_info = {
‘name’: vm.name,
}
vm_info[‘class_tag’] = self._parse_name_for_server_class(vm.name)
def _parse_name_for_server_class(self, guest_name):
‘’’
This is a hack to get around lack of support for tags.
Embed the tag in the name and parse it to set the server class - worker, master, server
Then map the simple group to the roles in the vmware_inventory/vmware_hosts file
@param guest_name: name of vmware guest instance. Corresponds to guest field in vsphere_guest.
‘’’
this could probably be read in from vmware.ini file but fine for now
DEFINED_SERVER_CLASS_TAGS = [‘master’, ‘server’, ‘worker’, ‘solutions’]
for class_tag in DEFINED_SERVER_CLASS_TAGS:
if guest_name.find(class_tag) != -1:
return class_tag
return None
at the bottom of
def get_inventory():
Group by class_tag
vm can only be in one class
vm_class_tag = vm_info.get(‘vmware_class_tag’, None)
if vm_class_tag:
self._add_child(inv, vm_group, ‘class_tag’)
self._add_child(inv, ‘class_tag’, vm_class_tag)
self._add_host(inv, vm_class_tag, vm.name)