Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_vm_inventory - fixed hostgroups being created automatically when the with_path option is enabled #2248

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions changelogs/fragments/1688-fix-auto-host-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- vmware_vm_inventory - Fixed unwanted hostgroups being created automatically when the with_path option is enabled.
(https://github.com/ansible-collections/community.vmware/issues/1688).
21 changes: 0 additions & 21 deletions plugins/inventory/vmware_vm_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@
from ansible.module_utils.common.dict_transformations import camel_dict_to_snake_dict
from ansible.module_utils.common.dict_transformations import _snake_to_camel
from ansible.utils.display import Display
from ansible.module_utils.six import text_type
from ansible_collections.community.vmware.plugins.plugin_utils.inventory import (
to_nested_dict,
to_flatten_dict,
Expand Down Expand Up @@ -929,26 +928,6 @@ def _populate_host_properties(self, host_properties, host):
# Create groups based on variable values and add the corresponding hosts to it
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), host_properties, host, strict=strict)

with_path = self.get_option('with_path')
if with_path:
parents = host_properties['path'].split('/')
if parents:
if isinstance(with_path, text_type):
parents = [with_path] + parents

c_name = self._sanitize_group_name('/'.join(parents))
c_group = self.inventory.add_group(c_name)
self.inventory.add_host(host, c_group)
parents.pop()

while len(parents) > 0:
p_name = self._sanitize_group_name('/'.join(parents))
p_group = self.inventory.add_group(p_name)

self.inventory.add_child(p_group, c_group)
c_group = p_group
parents.pop()

can_sanitize = self.get_option('with_sanitized_property_name')

# Sanitize host properties: to snake case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
assert:
that:
- "'path' in test_host.value"
- "'my_center' in test_host.value.group_names"
- "'my_center' in test_host.value.path"

- name: Inventory 'with_nested_properties' option
include_tasks: build_inventory.yml
Expand Down