# included task vars and templates

**URL:** <https://forum.ansible.com/t/included-task-vars-and-templates/11561>\
**Category:** Ansible Project\
**Created:** [May 19, 2012, 7:03pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561 "2012-05-19T19:03:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 7:03pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/1 "2012-05-19T19:03:18Z")

</div>

Given this playbook:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 19, 2012, 7:41pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/2 "2012-05-19T19:41:41Z")

</div>

--Michael

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 7:51pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/3 "2012-05-19T19:51:25Z")

</div>

Hmmm… any ideas for a workaround?

What I’m doing is dividing my playbooks into logical groups of tasks. But sometimes one playbook needs to include tasks from a different group of tasks, e.g., slapd project needs to access openssl project to generate the certificate. Within the context of the openssl project, I have a var $cn that contains the common name for the certificate. But in the slapd project the corresponding value is in the $fqdn var. Somehow I need to pass the fqdn value to the openssl templates, where cn is expected.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 19, 2012, 8:02pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/4 "2012-05-19T20:02:41Z")

</div>

--Michael

> Hmmm.... any ideas for a workaround?

Nothing easy or elegant, nor that I would recommend to anyone, but if you need to get going:

Calling the setup module would allow you to persist the settings to another metadata file with the variables you chose  
to pass down.

setup metadata=/tmp/some\_path a=2 b=3 c=$somevar

Would gather facts + a, b, and c, but you would not have other variables in the template unless you passed them to setup.

(If you leave off metadata will use the default path, which would lose variables for other template ops, and would be bad.)

--Michael

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 19, 2012, 8:05pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/5 "2012-05-19T20:05:54Z")

</div>

You will have to pass metadata=\<path\> to the template call also, using the same path you fed 'setup'.

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 8:07pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/6 "2012-05-19T20:07:31Z")

</div>

Yeah… not very elegant, especially since I’d lose all my regular setup vars.

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 8:10pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/7 "2012-05-19T20:10:37Z")

</div>

If we had overlord-local modules, I could write one that would take in vars and return them as facts. 😉

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 19, 2012, 8:14pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/8 "2012-05-19T20:14:01Z")

</div>

(dev internals discussion, kind of sort of)

So it was once in plan that the template "module" could take key=value options that were used only for that call.

If so, you could do:

template src=… dest=… biz=$biz

And use those variables in addition to whatever else.

I'd like to have that feature back, it's not the fix for this particular problem by any means, but it would be nice. If you can make that happen by Tuesday or so, I can probably get that merged into 0.4.

Even if not -- it's a workable fix we can have on devel.

--Michael

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 8:17pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/9 "2012-05-19T20:17:41Z")

</div>

Yes, that would work as a workaround. I’ll try to do that.

---

<div class="post-metadata">

**Author:** ![Matthew\_Williams](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@Matthew\_Williams](https://forum.ansible.com/u/Matthew_Williams)\
**Post date:** [May 19, 2012, 11:57pm UTC](https://forum.ansible.com/t/included-task-vars-and-templates/11561/10 "2012-05-19T23:57:40Z")

</div>

OK, so the best I can tell so far, the include params are parsed early – before the setup step, so my host vars are not even getting passed. Am I right? E.g., if I have a host var of $foo, I don’t think I can do this:

tasks:

- include: bar.yaml biz=$foo
