1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

add simple prefix filtering to vmware inventory

Significantly speeds up inventory collection on systems with many
excluded machines.
This commit is contained in:
Tom Paine 2015-06-17 18:41:54 +01:00
parent 0c27315648
commit 410285ecd6
2 changed files with 13 additions and 1 deletions

View file

@ -23,6 +23,10 @@ guests_only = True
# caching will be disabled. # caching will be disabled.
#cache_dir = ~/.cache/ansible #cache_dir = ~/.cache/ansible
# Specify a prefix filter. Any VMs with names beginning with this string will
# not be returned.
# prefix_filter = test_
[auth] [auth]
# Specify hostname or IP address of vCenter/ESXi server. A port may be # Specify hostname or IP address of vCenter/ESXi server. A port may be

View file

@ -305,6 +305,11 @@ class VMwareInventory(object):
else: else:
vm_group = default_group + '_vm' vm_group = default_group + '_vm'
if self.config.has_option('defaults', 'prefix_filter'):
prefix_filter = self.config.get('defaults', 'prefix_filter')
else:
prefix_filter = None
# Loop through physical hosts: # Loop through physical hosts:
for host in HostSystem.all(self.client): for host in HostSystem.all(self.client):
@ -318,6 +323,9 @@ class VMwareInventory(object):
# Loop through all VMs on physical host. # Loop through all VMs on physical host.
for vm in host.vm: for vm in host.vm:
if prefix_filter:
if vm.name.startswith( prefix_filter ):
continue
self._add_host(inv, 'all', vm.name) self._add_host(inv, 'all', vm.name)
self._add_host(inv, vm_group, vm.name) self._add_host(inv, vm_group, vm.name)
vm_info = self._get_vm_info(vm) vm_info = self._get_vm_info(vm)