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
This commit is contained in:
tikitavi 2019-03-12 21:02:44 +03:00 committed by Kubernetes Prow Robot
parent 44de04be89
commit 7b3e59ed0a

View file

@ -127,15 +127,14 @@ class KubesprayInventory(object):
if group == 'all': if group == 'all':
self.debug("Adding group {0}".format(group)) self.debug("Adding group {0}".format(group))
if group not in self.yaml_config: if group not in self.yaml_config:
self.yaml_config = {'all': all_dict = OrderedDict([('hosts', {}),
{'hosts': {}, ('vars', {'ansible_user': 'centos'}),
'vars': ('children', OrderedDict({}))])
{'ansible_user': 'centos'}, self.yaml_config = {'all': all_dict }
'children': {}}}
else: else:
self.debug("Adding group {0}".format(group)) self.debug("Adding group {0}".format(group))
if group not in self.yaml_config['all']['children']: 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): def get_host_id(self, host):
'''Returns integer host ID (without padding) from a given hostname.''' '''Returns integer host ID (without padding) from a given hostname.'''