# with\_first\_found and templates

**URL:** <https://forum.ansible.com/t/with-first-found-and-templates/16106>\
**Category:** Ansible Project\
**Created:** [September 3, 2014, 2:03pm UTC](https://forum.ansible.com/t/with-first-found-and-templates/16106 "2014-09-03T14:03:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [September 3, 2014, 2:03pm UTC](https://forum.ansible.com/t/with-first-found-and-templates/16106/1 "2014-09-03T14:03:49Z")

</div>

We've got a task like this:

&nbsp;&nbsp;- name: template TrustedHosts  
&nbsp;&nbsp;&nbsp;&nbsp;template: dest=/etc/opendkim/TrustedHosts src={{ item }} backup=yes  
&nbsp;&nbsp;&nbsp;&nbsp;with\_first\_found:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- TrustedHosts.{{ stack }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- TrustedHosts.default

There are three hosts that use the playbook this is in, and when Ansible  
gets to this task, it says

&nbsp;&nbsp;&nbsp;TASK: [../../shared/roles/opendkim | template TrustedHosts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [host3] =\> {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [host2] =\> {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [host3] =\> {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [host2] =\> {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [hos1] =\> {'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}  
&nbsp;&nbsp;&nbsp;&nbsp;fatal: [host1] =\> {'msg': 'One or more items failed.', 'failed': True, 'changed': False, 'results': [{'msg': 'unable to read /home/jsmift/ansible/shared/roles/opendkim/templates', 'failed': True}]}

(Hostnames changed to protect the innocent.)

It works fine if I change it to

&nbsp;&nbsp;- name: template TrustedHosts  
&nbsp;&nbsp;&nbsp;&nbsp;template: dest=/etc/opendkim/TrustedHosts src={{ item }} backup=yes  
&nbsp;&nbsp;&nbsp;&nbsp;with\_first\_found:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- ../templates/TrustedHosts.{{ stack }}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- ../templates/TrustedHosts.default

That suggests to me that it's searching relative to the 'files' directory  
of this role; I had expected it to search relative to the 'templates'  
directory, since this task uses the template module.

Should the initial task work as written (i.e. is this a bug)? If not, is  
there a better way to do this, or is "../templates" the right answer?

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 3, 2014, 4:15pm UTC](https://forum.ansible.com/t/with-first-found-and-templates/16106/2 "2014-09-03T16:15:26Z")

</div>

Hi Josh,

The various “with\_” operators in ansible are generic so this shouldn’t be specific to the template module, but that does seem a bit curious.

I amw ondering if it’s because with\_first\_found is not returning an os.path.abspath or has some weird logic in there.

Can you please file a bug on this one so we can look at it?

Thanks!

---

<div class="post-metadata">

**Author:** ![Josh\_Smift1](https://avatars.discourse-cdn.com/v4/letter/j/bcef8e/32.png) [@Josh\_Smift1](https://forum.ansible.com/u/Josh_Smift1)\
**Post date:** [September 3, 2014, 4:49pm UTC](https://forum.ansible.com/t/with-first-found-and-templates/16106/3 "2014-09-03T16:49:41Z")

</div>

> Can you please file a bug on this one so we can look at it?

Done: [https://github.com/ansible/ansible/issues/8879](https://github.com/ansible/ansible/issues/8879) (from my personal  
account, I don't have a work-related Github account at the moment).

Thanks!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-Josh (jbs@care.com)

This email is intended for the person(s) to whom it is addressed and may contain information that is PRIVILEGED or CONFIDENTIAL. Any unauthorized use, distribution, copying, or disclosure by any person other than the addressee(s) is strictly prohibited. If you have received this email in error, please notify the sender immediately by return email and delete the message and any attachments from your system.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 5, 2014, 1:17am UTC](https://forum.ansible.com/t/with-first-found-and-templates/16106/4 "2014-09-05T01:17:16Z")

</div>

Thanks, I’ve prioritized this one up a bit, will reply on the ticket as this progresses. Thanks!
