diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py index a5dd98a4469..39a863dd4b6 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)