fix script inventory plugin

fixes #25371

there is still better ways to do this, but this will 'unbreak' devel for now
pull/4420/head
Brian Coca 2017-06-05 18:25:48 -04:00
parent 9831e1597f
commit cf59f9765e
2 changed files with 11 additions and 11 deletions

View File

@ -73,7 +73,7 @@ class BaseInventoryPlugin(object):
def clear_cache(self): def clear_cache(self):
pass pass
def populate_host_vars(self, hosts, variables, group, port=None): def populate_host_vars(self, hosts, variables, group=None, port=None):
if hosts: if hosts:
for host in hosts: for host in hosts:

View File

@ -120,29 +120,29 @@ class InventoryModule(BaseInventoryPlugin):
group = None group = None
data_from_meta = None data_from_meta = None
# A "_meta" subelement may contain a variable "hostvars" which contains a hash for each host
# if this "hostvars" exists at all then do not call --host for each # host.
# This is for efficiency and scripts should still return data
# if called with --host for backwards compat with 1.2 and earlier.
for (group, gdata) in processed.items(): for (group, gdata) in processed.items():
if group == '_meta': if group == '_meta':
if 'hostvars' in processed: if 'hostvars' in gdata:
data_from_meta = processed['hostvars'] data_from_meta = gdata['hostvars']
else: else:
self._parse_group(group, gdata) self._parse_group(group, gdata)
# in Ansible 1.3 and later, a "_meta" subelement may contain
# a variable "hostvars" which contains a hash for each host
# if this "hostvars" exists at all then do not call --host for each
# host. This is for efficiency and scripts should still return data
# if called with --host for backwards compat with 1.2 and earlier.
for host in self._hosts: for host in self._hosts:
got = {} got = {}
if data_from_meta is None: if data_from_meta is None:
got = self.get_host_variables(path, host) got = self.get_host_variables(path, host)
else: else:
try: try:
got = processed.get(host, {}) got = data_from_meta.get(host, {})
except AttributeError as e: except AttributeError as e:
raise AnsibleError("Improperly formatted host information for %s: %s" % (host, to_native(e))) raise AnsibleError("Improperly formatted host information for %s: %s" % (host, to_native(e)))
self.populate_host_vars(host, got, group) self.populate_host_vars([host], got)
except Exception as e: except Exception as e:
raise AnsibleParserError(to_native(e)) raise AnsibleParserError(to_native(e))
@ -172,7 +172,7 @@ class InventoryModule(BaseInventoryPlugin):
for k, v in iteritems(data['vars']): for k, v in iteritems(data['vars']):
self.inventory.set_variable(group, k, v) self.inventory.set_variable(group, k, v)
if group != 'meta' and isinstance(data, dict) and 'children' in data: if group != '_meta' and isinstance(data, dict) and 'children' in data:
for child_name in data['children']: for child_name in data['children']:
self.inventory.add_group(child_name) self.inventory.add_group(child_name)
self.inventory.add_child(group, child_name) self.inventory.add_child(group, child_name)