# Remote template

**URL:** <https://forum.ansible.com/t/remote-template/13576>\
**Category:** Ansible Project\
**Created:** [September 30, 2013, 10:29am UTC](https://forum.ansible.com/t/remote-template/13576 "2013-09-30T10:29:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruno\_Dupuis](https://avatars.discourse-cdn.com/v4/letter/b/b77776/32.png) [@Bruno\_Dupuis](https://forum.ansible.com/u/Bruno_Dupuis)\
**Post date:** [September 30, 2013, 10:29am UTC](https://forum.ansible.com/t/remote-template/13576/1 "2013-09-30T10:29:06Z")

</div>

Hi,

Is there a practical way to use a remote file as a jinja template in template modules ?

Let’s explain my use case:

My application code requires configuration that may vary depending on the environment (dev/staging/prot)

I want to keep configuration defintion into application code, as j2 template, because it’s easier to maintain.

Those templates are deployed on the target machines along with the app, and then ansible creates final configuration files, using host/group variables.

Regards.

---

<div class="post-metadata">

**Author:** ![Brian\_Harring](https://avatars.discourse-cdn.com/v4/letter/b/71c47a/32.png) [@Brian\_Harring](https://forum.ansible.com/u/Brian_Harring)\
**Post date:** [September 30, 2013, 6:37pm UTC](https://forum.ansible.com/t/remote-template/13576/2 "2013-09-30T18:37:43Z")

</div>

> Hi,
> 
> Is there a practical way to use a remote file as a jinja template in  
> template modules ?

Combination of the fetch module and template module seems to be your  
options here. Specifically  
[http://www.ansibleworks.com/docs/modules.html#fetch](http://www.ansibleworks.com/docs/modules.html#fetch) .

> Let's explain my use case:
> 
> My application code requires configuration that may vary depending on the  
> environment (dev/staging/prot)
> 
> I want to keep configuration defintion into application code, as j2  
> template, because it's easier to maintain.
> 
> Those templates are deployed on the target machines along with the app,  
> and then ansible creates final configuration files, using host/group  
> variables.

Fun pattern; I'd be curious what your final implementation is for this. My  
first inclination is that of "just centralize it in the repo- say via git  
submodules", but that has it's own issues.

Cheers-  
~brian

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 30, 2013, 7:35pm UTC](https://forum.ansible.com/t/remote-template/13576/3 "2013-09-30T19:35:11Z")

</div>

+1 to submodules, this way your playbook repo would have access to the template and those hijinks would not be required.

---

<div class="post-metadata">

**Author:** ![vitaly\_bichov](https://avatars.discourse-cdn.com/v4/letter/v/cc9497/32.png) [@vitaly\_bichov](https://forum.ansible.com/u/vitaly_bichov)\
**Post date:** [July 23, 2015, 7:17am UTC](https://forum.ansible.com/t/remote-template/13576/4 "2015-07-23T07:17:23Z")

</div>

Hi,

I’m facing the same issue and wonder how you solved it?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 23, 2015, 12:17pm UTC](https://forum.ansible.com/t/remote-template/13576/5 "2015-07-23T12:17:28Z")

</div>

something like?

template: src={{lookup('uri', '[http://remote.com/file.j2](http://remote.com/file.j2)’}}

---

<div class="post-metadata">

**Author:** ![Hristo\_Stoyanov](https://avatars.discourse-cdn.com/v4/letter/h/c6cbf5/32.png) [@Hristo\_Stoyanov](https://forum.ansible.com/u/Hristo_Stoyanov)\
**Post date:** [November 27, 2015, 6:37am UTC](https://forum.ansible.com/t/remote-template/13576/6 "2015-11-27T06:37:22Z")

</div>

Can we do something like the “remote\_src” parameter added in the “copy” module with Ansible 2.0? The use of “fetch” seems like a pretty awkward workaround. See another legitimate use case for this here:  
[http://stackoverflow.com/questions/33163204/ansible-remote-templates](http://stackoverflow.com/questions/33163204/ansible-remote-templates)

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 27, 2015, 4:14pm UTC](https://forum.ansible.com/t/remote-template/13576/7 "2015-11-27T16:14:09Z")

</div>

that would require the remote machine to have jinja2 installed.
