Skip to content

Commit fdf247e

Browse files
Enhancement: Added option to not prepend group names with group_by option (#147)
1 parent b16825b commit fdf247e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

plugins/inventory/nb_inventory.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
- manufacturers
7474
- platforms
7575
default: []
76+
group_names_raw:
77+
description: Will not add the group_by choice name to the group names
78+
default: False
79+
type: boolean
80+
version_added: "0.2.0"
7681
query_filters:
7782
description: List of parameters passed to the query string (Multiple values may be separated by commas)
7883
type: list
@@ -614,7 +619,10 @@ def add_host_to_groups(self, host, hostname):
614619
continue
615620

616621
for sub_group in sub_groups:
617-
group_name = "_".join([group, sub_group])
622+
if self.group_names_raw:
623+
group_name = sub_group
624+
else:
625+
group_name = "_".join([group, sub_group])
618626
self.inventory.add_group(group=group_name)
619627
self.inventory.add_host(group=group_name, host=hostname)
620628

@@ -689,5 +697,6 @@ def parse(self, inventory, loader, path, cache=True):
689697

690698
# Filter and group_by options
691699
self.group_by = self.get_option("group_by")
700+
self.group_names_raw = self.get_option("group_names_raw")
692701
self.query_filters = self.get_option("query_filters")
693702
self.main()

0 commit comments

Comments
 (0)