# Recursive templates in roles?

**URL:** <https://forum.ansible.com/t/recursive-templates-in-roles/15860>\
**Category:** Ansible Developer\
**Created:** [August 5, 2014, 6:09am UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860 "2014-08-05T06:09:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [August 5, 2014, 6:09am UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/1 "2014-08-05T06:09:52Z")

</div>

Would be convenient to do this in a role:

`

- template: src=some\_templates dest=/path/to/remote/folder recurse=true  
`

And for it to pass the entire folder structure over while passing every file through jinja2. Is there anything in the way of this being implemented?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [August 7, 2014, 3:38pm UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/2 "2014-08-07T15:38:11Z")

</div>

Hi, thanks for the suggestion.

Right now, this is pretty much what the assemble module does, however each file in the assembled list is not templated. It would make more sense to me to add a template=yes option to that module, which would run the files through the template engine (if and only if the src files were not remote).

Could you please open a github issue for this feature request so that we can keep track of it?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [August 7, 2014, 4:04pm UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/3 "2014-08-07T16:04:14Z")

</div>

I do this:

- template: src={{item}} dest=/path/sdf/sdf/{{item}}with\_pipe: find /local/path/to/templates -type f  
​

---

<div class="post-metadata">

**Author:** ![Ryan\_VanGundy](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_VanGundy](https://forum.ansible.com/u/Ryan_VanGundy)\
**Post date:** [August 7, 2014, 4:46pm UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/4 "2014-08-07T16:46:52Z")

</div>

Brian, that’s clever! I’ll give that a shot. Is it idempotent?

I went ahead and added the feature request to do this in more of a pure ansible fashion. [https://github.com/ansible/ansible/issues/8497](https://github.com/ansible/ansible/issues/8497)

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [August 7, 2014, 5:09pm UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/5 "2014-08-07T17:09:41Z")

</div>

Yes, that would not replace templates that had not changed. Also, I believe the with\_fileglob would generally be a better solution there:

[http://docs.ansible.com/playbooks\_loops.html#looping-over-fileglobs](http://docs.ansible.com/playbooks_loops.html#looping-over-fileglobs)

Regarding your question on the ticket you opened, the assemble module only builds single files. So if you’re looking for more of a recursive copy function then the above is the way to do it. I would still like to keep that feature request open, as I believe it would be a useful option.

Thanks!

---

<div class="post-metadata">

**Author:** ![Steve\_Kieu](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@Steve\_Kieu](https://forum.ansible.com/u/Steve_Kieu)\
**Post date:** [November 2, 2015, 11:37pm UTC](https://forum.ansible.com/t/recursive-templates-in-roles/15860/6 "2015-11-02T23:37:16Z")

</div>

Looks like it does not work for me, for some reason with\_pipe does nto return a list. Please help if you have any idea …
