From ddb3764039eb18cbeaf90269901fb57919389999 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Thu, 13 Sep 2018 15:38:52 -0400 Subject: [PATCH] avoid empty groups in json output (#45621) they get confused as hosts by script plugin fixes #45601 --- changelogs/fragments/no_empty_groups.yml | 2 ++ lib/ansible/cli/inventory.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 changelogs/fragments/no_empty_groups.yml diff --git a/changelogs/fragments/no_empty_groups.yml b/changelogs/fragments/no_empty_groups.yml new file mode 100644 index 00000000000..0c80f646507 --- /dev/null +++ b/changelogs/fragments/no_empty_groups.yml @@ -0,0 +1,2 @@ +bugfixes: + - avoid empty groups in ansbile-inventory JSON output as they will be interpreted as hosts diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py index 788a9fa9232..6590c98103c 100644 --- a/lib/ansible/cli/inventory.py +++ b/lib/ansible/cli/inventory.py @@ -329,6 +329,8 @@ class InventoryCLI(CLI): results[group.name]['vars'] = self._get_group_variables(group) self._remove_empty(results[group.name]) + if not results[group.name]: + del results[group.name] return results