mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
Merge pull request #462 from AlanCoding/bad_groups
handle additional cases of inv script output
This commit is contained in:
@@ -185,10 +185,20 @@ class AnsibleInventoryLoader(object):
|
|||||||
data.setdefault('_meta', {})
|
data.setdefault('_meta', {})
|
||||||
data['_meta'].setdefault('hostvars', {})
|
data['_meta'].setdefault('hostvars', {})
|
||||||
logger.warning('Re-calling script for hostvars individually.')
|
logger.warning('Re-calling script for hostvars individually.')
|
||||||
for group_name, group_dict in data.iteritems():
|
for group_name, group_data in data.iteritems():
|
||||||
if group_name == '_meta':
|
if group_name == '_meta':
|
||||||
continue
|
continue
|
||||||
for hostname in group_dict.get('hosts', []):
|
|
||||||
|
if isinstance(group_data, dict):
|
||||||
|
group_host_list = group_data.get('hosts', [])
|
||||||
|
elif isinstance(group_data, list):
|
||||||
|
group_host_list = group_data
|
||||||
|
else:
|
||||||
|
logger.warning('Group data for "%s" is not a dict or list',
|
||||||
|
group_name)
|
||||||
|
group_host_list = []
|
||||||
|
|
||||||
|
for hostname in group_host_list:
|
||||||
logger.debug('Obtaining hostvars for %s' % hostname.encode('utf-8'))
|
logger.debug('Obtaining hostvars for %s' % hostname.encode('utf-8'))
|
||||||
hostdata = self.command_to_json(
|
hostdata = self.command_to_json(
|
||||||
base_args + ['--host', hostname.encode("utf-8")]
|
base_args + ['--host', hostname.encode("utf-8")]
|
||||||
@@ -196,7 +206,7 @@ class AnsibleInventoryLoader(object):
|
|||||||
if isinstance(hostdata, dict):
|
if isinstance(hostdata, dict):
|
||||||
data['_meta']['hostvars'][hostname] = hostdata
|
data['_meta']['hostvars'][hostname] = hostdata
|
||||||
else:
|
else:
|
||||||
self.logger.warning(
|
logger.warning(
|
||||||
'Expected dict of vars for host "%s" when '
|
'Expected dict of vars for host "%s" when '
|
||||||
'calling with `--host`, got %s instead',
|
'calling with `--host`, got %s instead',
|
||||||
k, str(type(data))
|
k, str(type(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user