Avoid duplicated recursive calls in inventory CLI (#48598)

This commit is contained in:
Alan Rominger 2018-11-30 05:36:19 -05:00 committed by John R Barker
parent b4ce4e1571
commit d536be6530

View file

@ -324,6 +324,8 @@ class InventoryCLI(CLI):
def json_inventory(self, top):
seen = set()
def format_group(group):
results = {}
results[group.name] = {}
@ -332,7 +334,9 @@ class InventoryCLI(CLI):
results[group.name]['children'] = []
for subgroup in sorted(group.child_groups, key=attrgetter('name')):
results[group.name]['children'].append(subgroup.name)
results.update(format_group(subgroup))
if subgroup.name not in seen:
results.update(format_group(subgroup))
seen.add(subgroup.name)
if self.options.export:
results[group.name]['vars'] = self._get_group_variables(group)