diff options
author | Brian Coca <brian.coca+git@gmail.com> | 2017-11-01 17:48:50 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2017-11-02 17:58:19 -0400 |
commit | 07674f5062aaf87564e22c017b72803e8a3243b5 (patch) | |
tree | 6333e954c6e67172ff4fcd29538012d9ba03a5be | |
parent | dd930344b64c3f5b4b5a1fd11d8b13a524eee963 (diff) | |
download | ansible-07674f5062aaf87564e22c017b72803e8a3243b5.tar.gz |
ini plugin should recursively instantiate pending
solves inconsistent behaviour on ini host format depending on definition order
fixes #32196
(cherry picked from commit 9d28973b5e8bc8844395206b39c2ff09d1de5e0f)
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | lib/ansible/plugins/inventory/ini.py | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b6678611d6..34273604d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,8 @@ Ansible Changes By Release (https://github.com/ansible/ansible/pull/32190) * Fix failure during upgrade due to NON_RESPONSIVE state for ovirt_hosts module (https://github.com/ansible/ansible/pull/32192) +* ini inventory format now correclty handles group creation w/o need for specific orders + https://github.com/ansible/ansible/pull/32471 <a id="2.4.1"></a> diff --git a/lib/ansible/plugins/inventory/ini.py b/lib/ansible/plugins/inventory/ini.py index 578f899b86..a3374a8408 100644 --- a/lib/ansible/plugins/inventory/ini.py +++ b/lib/ansible/plugins/inventory/ini.py @@ -193,9 +193,7 @@ class InventoryModule(BaseFileInventoryPlugin): if groupname in pending_declarations and state != 'vars': if pending_declarations[groupname]['state'] == 'children': - for parent in pending_declarations[groupname]['parents']: - self.inventory.add_child(parent, groupname) - del pending_declarations[groupname] + self._add_pending_children(groupname, pending_declarations) continue elif line.startswith('[') and line.endswith(']'): @@ -248,6 +246,13 @@ class InventoryModule(BaseFileInventoryPlugin): elif decl['state'] == 'children': raise AnsibleError("%s:%d: Section [%s:children] includes undefined group: %s" % (path, decl['line'], decl['parents'].pop(), decl['name'])) + def _add_pending_children(self, group, pending): + for parent in pending[group]['parents']: + self.inventory.add_child(parent, group) + if parent in pending and pending[parent]['state'] == 'children': + self._add_pending_children(parent, pending) + del pending[group] + def _parse_group_name(self, line): ''' Takes a single line and tries to parse it as a group name. Returns the |