From 7b3e59ed0a5b9223d70571197be8f5a7fad0e001 Mon Sep 17 00:00:00 2001 From: tikitavi Date: Tue, 12 Mar 2019 21:02:44 +0300 Subject: [PATCH] fix inventory script (#4339) - fix order of entries when the new yaml file is created - fix group in case there are no hosts in it --- contrib/inventory_builder/inventory.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/contrib/inventory_builder/inventory.py b/contrib/inventory_builder/inventory.py index 118a986dd..32213bdd1 100644 --- a/contrib/inventory_builder/inventory.py +++ b/contrib/inventory_builder/inventory.py @@ -127,15 +127,14 @@ class KubesprayInventory(object): if group == 'all': self.debug("Adding group {0}".format(group)) if group not in self.yaml_config: - self.yaml_config = {'all': - {'hosts': {}, - 'vars': - {'ansible_user': 'centos'}, - 'children': {}}} + all_dict = OrderedDict([('hosts', {}), + ('vars', {'ansible_user': 'centos'}), + ('children', OrderedDict({}))]) + self.yaml_config = {'all': all_dict } else: self.debug("Adding group {0}".format(group)) if group not in self.yaml_config['all']['children']: - self.yaml_config['all']['children'][group] = {'hosts': None} + self.yaml_config['all']['children'][group] = {'hosts': {}} def get_host_id(self, host): '''Returns integer host ID (without padding) from a given hostname.'''