# jinja syntax error in lookup template says "can't read file"

**URL:** <https://forum.ansible.com/t/jinja-syntax-error-in-lookup-template-says-cant-read-file/18682>\
**Category:** Ansible Project\
**Created:** [July 6, 2015, 2:55am UTC](https://forum.ansible.com/t/jinja-syntax-error-in-lookup-template-says-cant-read-file/18682 "2015-07-06T02:55:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [July 6, 2015, 2:55am UTC](https://forum.ansible.com/t/jinja-syntax-error-in-lookup-template-says-cant-read-file/18682/1 "2015-07-06T02:55:05Z")

</div>

I have template that contains

`

- job\_name: nodes  
consul\_sd\_configs:  
{% for cenv in prometheus\_consul\_dcs %}  
{% endfor %}  
`

This loads fine with

`  
prometheus\_yml: “{{lookup(‘template’, ‘…/files/prometheus/prometheus.yml.j2’)}}”

`

But when I add a loop

`

- job\_name: nodes  
consul\_sd\_configs:  
{% for cenv in prometheus\_consul\_dcs %}  
{% endfor %}  
`

I get an error saying the file can’t read.

`  
TASK: [prometheus | Create prometheus configuration file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [10.0.196.193] =\> Failed to template {{lookup(‘template’, ‘…/files/prometheus/prometheus.yml.j2’)}}: unable to read /Users/bkaplan/si/ops/ansible/roles/prometheus/files/prometheus/prometheus.yml.j2  
`

I guess one could argue that “can’t read” is not the same as “can’t find” and this should be interpreted as an error in the file. Is there any way to get the actual error from jinja?

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [July 6, 2015, 2:59am UTC](https://forum.ansible.com/t/jinja-syntax-error-in-lookup-template-says-cant-read-file/18682/2 "2015-07-06T02:59:16Z")

</div>

Seems the trick is to run the template thru the template action directly:

`template: src: ../files/prometheus/prometheus.yml.j2 dest: /tmp/p.yml`

Then you get a proper error message:

`TASK: [TEST TEST] ************************************************************* fatal: [10.0.196.193] => {'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'prometheus_consul_dcs' is undefined", 'failed': True}`
