mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Make hostvars work post refactoring
This commit is contained in:
parent
b0eedfbf92
commit
6e84374c2a
2 changed files with 5 additions and 12 deletions
|
@ -552,9 +552,11 @@ class Runner(object):
|
||||||
host_variables = self.inventory.get_variables(host)
|
host_variables = self.inventory.get_variables(host)
|
||||||
port = host_variables.get('ansible_ssh_port', self.remote_port)
|
port = host_variables.get('ansible_ssh_port', self.remote_port)
|
||||||
inject = self.setup_cache[host].copy()
|
inject = self.setup_cache[host].copy()
|
||||||
|
inject['hostvars'] = self.setup_cache
|
||||||
inject.update(host_variables)
|
inject.update(host_variables)
|
||||||
inject.update(self.module_vars)
|
inject.update(self.module_vars)
|
||||||
|
|
||||||
|
|
||||||
items = self.module_vars.get('items', [])
|
items = self.module_vars.get('items', [])
|
||||||
if isinstance(items, basestring) and items.startswith("$"):
|
if isinstance(items, basestring) and items.startswith("$"):
|
||||||
items = items.replace("$","")
|
items = items.replace("$","")
|
||||||
|
@ -646,7 +648,8 @@ class Runner(object):
|
||||||
self.callbacks.on_unreachable(host, result.result)
|
self.callbacks.on_unreachable(host, result.result)
|
||||||
else:
|
else:
|
||||||
data = result.result
|
data = result.result
|
||||||
result.result['item'] = inject.get('item', None)
|
if 'item' in inject:
|
||||||
|
result.result['item'] = inject['item']
|
||||||
if 'skipped' in data:
|
if 'skipped' in data:
|
||||||
self.callbacks.on_skipped(result.host)
|
self.callbacks.on_skipped(result.host)
|
||||||
elif not result.is_successful():
|
elif not result.is_successful():
|
||||||
|
|
|
@ -192,16 +192,6 @@ def varReplace(raw, vars):
|
||||||
|
|
||||||
return ''.join(done)
|
return ''.join(done)
|
||||||
|
|
||||||
def _template(text, vars):
|
|
||||||
''' run a text buffer through the templating engine '''
|
|
||||||
|
|
||||||
if vars is None:
|
|
||||||
raise Exception('vars is none')
|
|
||||||
vars = vars.copy()
|
|
||||||
# FIXME: do this in runner code
|
|
||||||
vars['hostvars'] = vars.get('setup_cache', {})
|
|
||||||
return varReplace(unicode(text), vars)
|
|
||||||
|
|
||||||
def template(text, vars):
|
def template(text, vars):
|
||||||
''' run a text buffer through the templating engine until it no longer changes '''
|
''' run a text buffer through the templating engine until it no longer changes '''
|
||||||
|
|
||||||
|
@ -212,7 +202,7 @@ def template(text, vars):
|
||||||
if (depth > 20):
|
if (depth > 20):
|
||||||
raise errors.AnsibleError("template recursion depth exceeded")
|
raise errors.AnsibleError("template recursion depth exceeded")
|
||||||
prev_text = text
|
prev_text = text
|
||||||
text = _template(text, vars)
|
text = varReplace(unicode(text), vars)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def template_from_file(basedir, path, vars):
|
def template_from_file(basedir, path, vars):
|
||||||
|
|
Loading…
Add table
Reference in a new issue