Remote template

827 views
Skip to first unread message

Bruno Dupuis

unread,
Sep 30, 2013, 6:29:06 AM9/30/13
to ansible...@googlegroups.com
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.

--
Bruno

Brian Harring

unread,
Sep 30, 2013, 2:37:43 PM9/30/13
to ansible...@googlegroups.com
On Mon, Sep 30, 2013 at 6:29 AM, Bruno Dupuis <br...@botify.com> wrote:
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 .
 
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

Michael DeHaan

unread,
Sep 30, 2013, 3:35:11 PM9/30/13
to ansible...@googlegroups.com
+1 to submodules, this way your playbook repo would have access to the template and those hijinks would not be required.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

vitaly bichov

unread,
Jul 23, 2015, 7:38:05 AM7/23/15
to Ansible Project, br...@botify.com
Hi,

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

Brian Coca

unread,
Jul 23, 2015, 8:17:32 AM7/23/15
to Ansible Project, br...@botify.com
something like?

template: src={{lookup('uri', 'http://remote.com/file.j2'}}
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a7a24228-78b0-4482-91e9-57b76fc1cdfc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Hristo Stoyanov

unread,
Nov 27, 2015, 1:37:22 AM11/27/15
to Ansible Project, br...@botify.com
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:

Brian Coca

unread,
Nov 27, 2015, 11:14:14 AM11/27/15
to Ansible Project, br...@botify.com
that would require the remote machine to have jinja2 installed.

On Thu, Nov 26, 2015 at 10:37 PM, Hristo Stoyanov <hr.st...@gmail.com> wrote:
> 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
>
--
Brian Coca
Reply all
Reply to author
Forward
0 new messages