# Utilizing a template from a module

**URL:** <https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729>\
**Category:** Ansible Developer\
**Created:** [July 21, 2014, 7:10pm UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729 "2014-07-21T19:10:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Dewey](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@John\_Dewey](https://forum.ansible.com/u/John_Dewey)\
**Post date:** [July 21, 2014, 7:10pm UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729/1 "2014-07-21T19:10:42Z")

</div>

I am writing a module which builds a config file. This template requires a bit of logic to determine the proper directives to include/exclude. This is a no-brainer in jinja, but fairly complex in pure stdlib. However, modules look to execute on the target-host, so installing jinja as a requirement doesn’t seem ideal.

Has anyone had success levering templates inside a custom module? Ideally it is evaluated on the host executing the ansible run, where we have access to jinja and template’s idempotency.

John

---

<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:** [July 21, 2014, 7:19pm UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729/2 "2014-07-21T19:19:51Z")

</div>

templates get built on ‘master’, you do not need jinja on the targets​

---

<div class="post-metadata">

**Author:** ![John\_Dewey](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@John\_Dewey](https://forum.ansible.com/u/John_Dewey)\
**Post date:** [July 21, 2014, 7:21pm UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729/3 "2014-07-21T19:21:57Z")

</div>

I don’t see an example of how to do this from another module. Writing this as a task is trivial. I want to write a module which utilizes template functionality.

---

<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:** [July 21, 2014, 11:18pm UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729/4 "2014-07-21T23:18:29Z")

</div>

It seems your module may wish to just require jinja2. Action plugins are large overhead that are not intended to be written frequently, mostly there to facilitate server-side heavy lifting.

However, from discussion, I believe you’re trying to write a logrotate module - to me, logrotate.d is probably easiest to just template, .d directory systems are magic when available, making much of the module unneeded.

---

<div class="post-metadata">

**Author:** ![John\_Dewey](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@John\_Dewey](https://forum.ansible.com/u/John_Dewey)\
**Post date:** [July 22, 2014, 2:47am UTC](https://forum.ansible.com/t/utilizing-a-template-from-a-module/15729/5 "2014-07-22T02:47:25Z")

</div>

Yeah, you are right. I could simply require jinja2, I just felt it was somewhat of an unnecessary dep. I found it somewhat difficult to cleanly implement a template[1] in pure stdlib, which led me to this original post. Thx for the advice Brian and Michael.

[1] [https://github.com/retr0h/ansible-logrotate/blob/master/templates/logrotate.conf.j2](https://github.com/retr0h/ansible-logrotate/blob/master/templates/logrotate.conf.j2)
