Work in progress on merging changed_when.
This commit is contained in:
parent
88720516a1
commit
7f462a346a
3 changed files with 8 additions and 6 deletions
|
@ -528,7 +528,8 @@ class Runner(object):
|
|||
self.conditional = [ self.conditional ]
|
||||
|
||||
for cond in self.conditional:
|
||||
if not utils.check_conditional(cond, self.basedir, inject):
|
||||
|
||||
if not utils.check_conditional(cond, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars):
|
||||
result = utils.jsonify(dict(changed=False, skipped=True))
|
||||
self.callbacks.on_skipped(host, inject.get('item',None))
|
||||
return ReturnData(host=host, result=result)
|
||||
|
@ -636,8 +637,7 @@ class Runner(object):
|
|||
if 'stdout' in data:
|
||||
data['stdout_lines'] = data['stdout'].splitlines()
|
||||
inject[register] = data
|
||||
changed = template.template(self.basedir, changed_when, inject, fail_on_undefined=self.error_on_undefined_vars)
|
||||
data['changed'] = utils.check_conditional(changed)
|
||||
data['changed'] = utils.check_conditional(changed_when, self.basedir, inject, fail_on_undefined=self.error_on_undefined_vars)
|
||||
|
||||
if is_chained:
|
||||
# no callbacks
|
||||
|
|
|
@ -58,7 +58,7 @@ class ActionModule(object):
|
|||
data = {}
|
||||
data.update(inject)
|
||||
data.update(inject['hostvars'][host])
|
||||
if not check_conditional(self.runner.basedir, self.runner.conditional, data):
|
||||
if not check_conditional(self.runner.basedir, self.runner.conditional, data, fail_on_undefined=self.runner.error_on_undefined_vars):
|
||||
continue
|
||||
group_name = template.template(self.runner.basedir, args['key'], data)
|
||||
group_name = group_name.replace(' ','-')
|
||||
|
|
|
@ -155,16 +155,18 @@ def is_changed(result):
|
|||
|
||||
return (result.get('changed', False) in [ True, 'True', 'true'])
|
||||
|
||||
def check_conditional(conditional, basedir, inject):
|
||||
def check_conditional(conditional, basedir, inject, fail_on_undefined=False):
|
||||
|
||||
if conditional.startswith("jinja2_compare"):
|
||||
conditional = conditional.replace("jinja2_compare ","")
|
||||
# allow variable names
|
||||
if conditional in inject:
|
||||
conditional = inject[conditional]
|
||||
conditional = template.template(basedir, conditional, inject)
|
||||
print "INJECTIFYING: %s" % inject
|
||||
conditional = template.template(basedir, conditional, inject, fail_on_undefined=fail_on_undefined)
|
||||
# a Jinja2 evaluation that results in something Python can eval!
|
||||
presented = "{% if " + conditional + " %} True {% else %} False {% endif %}"
|
||||
return presented
|
||||
|
||||
if not isinstance(conditional, basestring):
|
||||
return conditional
|
||||
|
|
Loading…
Reference in a new issue