Skip to content

Commit

Permalink
Fix nb_inventory group_by by site_group (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmerolle authored Feb 25, 2023
1 parent 3a4da61 commit 3477e82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/issue-951.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fix nb_inventory group_by by site_group (#951)
8 changes: 5 additions & 3 deletions plugins/inventory/nb_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__metaclass__ = type

DOCUMENTATION = """
name: nb_inventory
name: nb_inventory
author:
- Remy Leone (@sieben)
- Anthony Ruhier (@Anthony25)
Expand Down Expand Up @@ -1668,11 +1668,12 @@ def generate_group_name(self, grouping, group):

def add_host_to_groups(self, host, hostname):
site_group_by = self._pluralize_group_by("site")
site_group_group_by = self._pluralize_group_by("site_group")

for grouping in self.group_by:
# Don't handle regions here since no hosts are ever added to region groups
# Sites and locations are also specially handled in the main()
if grouping in ["region", site_group_by, "location", "site_group"]:
if grouping in ["region", site_group_by, "location", site_group_group_by]:
continue

if grouping not in self.group_extractors:
Expand Down Expand Up @@ -1892,11 +1893,12 @@ def main(self):
# - the location groups are added as sub-groups of sites
# So, we need to make sure we're also grouping by sites if regions or locations are enabled
site_group_by = self._pluralize_group_by("site")
site_group_group_by = self._pluralize_group_by("site")
if (
site_group_by in self.group_by
or "location" in self.group_by
or "region" in self.group_by
or "site_group" in self.group_by
or site_group_group_by in self.group_by
):
self._add_site_groups()

Expand Down

0 comments on commit 3477e82

Please sign in to comment.