From d536be6530a794807885bfddfc6db359f7125645 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 30 Nov 2018 05:36:19 -0500 Subject: [PATCH] Avoid duplicated recursive calls in inventory CLI (#48598) --- lib/ansible/cli/inventory.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py index a5dd98a446..39a863dd4b 100644 --- a/lib/ansible/cli/inventory.py +++ b/lib/ansible/cli/inventory.py @@ -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)