<p dir="auto">The change to <code class="notranslate">utils/template.py</code> introduced in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="23297467" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible/issues/5059" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible/issues/5059/hovercard" href="https://github.com/ansible/ansible/issues/5059">#5059</a> swallows errors about variable lookups. This causes unexpected issues later on. In my case a file is unexpectedly empty without an error.</p>
<p dir="auto">I think AnsibleErrors should be passed on like this::</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="def lookup(name, *args, **kwargs):
    from ansible import utils
    instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
    vars = kwargs.get('vars', None)

    if instance is not None:
        # safely catch run failures per #5059
        try:
            ran = instance.run(*args, inject=vars, **kwargs)
        except errors.AnsibleError:
            raise
        except Exception, e:
            ran = None
        if ran:
            ran = &quot;,&quot;.join(ran)
        return ran
    else:
        raise errors.AnsibleError(&quot;lookup plugin (%s) not found&quot; % name)"><pre class="notranslate"><code class="notranslate">def lookup(name, *args, **kwargs):
    from ansible import utils
    instance = utils.plugins.lookup_loader.get(name.lower(), basedir=kwargs.get('basedir',None))
    vars = kwargs.get('vars', None)

    if instance is not None:
        # safely catch run failures per #5059
        try:
            ran = instance.run(*args, inject=vars, **kwargs)
        except errors.AnsibleError:
            raise
        except Exception, e:
            ran = None
        if ran:
            ran = ",".join(ran)
        return ran
    else:
        raise errors.AnsibleError("lookup plugin (%s) not found" % name)
</code></pre></div>
<p dir="auto">That way typos in variable names or in the file name show up again.</p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.7 (devel <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/ansible/ansible/commit/a6a1e240c68e935b9afde6b85f64ee9820db2dea/hovercard" href="https://github.com/ansible/ansible/commit/a6a1e240c68e935b9afde6b85f64ee9820db2dea"><tt>a6a1e24</tt></a>) last updated 2014/05/12 10:59:56 (GMT -400)</p>
<p dir="auto">This happens in 1.6 as well.</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">OSX 10.9.2</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">Errors in templates are not propagated when using the template lookup plugin, which returns an empty string instead. Errors in these templates can be very difficult to debug as a result.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">ansible-playbook -vvv -i inventory/local pb_test.yml</p>
<p dir="auto"><a href="https://gist.github.com/scottanderson42/c1d172aa56916a258ff1">https://gist.github.com/scottanderson42/c1d172aa56916a258ff1</a></p>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">The first task should fail as the variable does_not_exist is not set.</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">The lookup task returns an empty string when the variable is not set instead of failing.</p>
<p dir="auto">(sp_devops)GoatRodeo:devops anderson (development)$ ansible-playbook -vvv -i inventory/local pb_test.yml</p>
<p dir="auto">PLAY [127.0.0.1] **************************************************************</p>
<p dir="auto">TASK: [debug msg=] ************************************************************<br>
ok: [127.0.0.1] =&gt; {<br>
"msg": ""<br>
}</p>
<p dir="auto">PLAY [127.0.0.1] **************************************************************</p>
<p dir="auto">TASK: [debug msg=This does not exist: 42<br>
] ************************************<br>
ok: [127.0.0.1] =&gt; {<br>
"msg": "This"<br>
}</p>
<p dir="auto">PLAY RECAP ********************************************************************<br>
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=0</p>