# missing vars and utils.template

**URL:** <https://forum.ansible.com/t/missing-vars-and-utils-template/11560>\
**Category:** Ansible Project\
**Created:** [May 19, 2012, 2:50pm UTC](https://forum.ansible.com/t/missing-vars-and-utils-template/11560 "2012-05-19T14:50:00Z")\
**Posts on this page:** 4\
**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, 2:50pm UTC](https://forum.ansible.com/t/missing-vars-and-utils-template/11560/1 "2012-05-19T14:50:00Z")

</div>

I just realized for the thousandth time or thereabouts that utils.template silently lets undefined vars pass through playbooks. I’m not sure what the best solution would be, but I see a couple possible solutions:

GIven the following action without ${foo} being defined:

action: copy src=${foo} dest=/some/path

Currently this tries to copy the literal file ${foo}, which of course fails.

I think utils.template could do one of the following to make what’s happening a little more obvious:

1. Throw an error and exit if it encounters an undefined var
2. Substitute something like this: \<undefined var: $foo\>

Personally, I like things to fail early, so #1 would be my preference. An undefined var is almost certainly going to prevent the task from completing anyway.

---

<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, 3:06pm UTC](https://forum.ansible.com/t/missing-vars-and-utils-template/11560/2 "2012-05-19T15:06:40Z")

</div>

This is actually desired behavior.

Suppose you are templating a Perl script with “$foo” in it, you don’t want $foo replaced unless it matches a variable.

---

<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, 3:10pm UTC](https://forum.ansible.com/t/missing-vars-and-utils-template/11560/3 "2012-05-19T15:10:58Z")

</div>

In a jinja2 template, I agree (and it deals with this by using {{ }} for jinja vars). But It’s unlikely that we will be feeding in a perl script to utils.template (e.g., as part of a path name or an arg to a module). Maybe I’m just off though.

---

<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, 3:23pm UTC](https://forum.ansible.com/t/missing-vars-and-utils-template/11560/4 "2012-05-19T15:23:17Z")

</div>

You would be surprised what people ask for. Got one request for turning off varReplace for exactly that reason. I said no.

That being said, I can see this causing a fair amount of problems.

And generally I find whenever I hear a voice in my head saying “you could make that an option”, that makes things extra confusing.

So I think we pick our current behavior.

It’s what staging environments are for anyway. Or that vagrant-ansible plugin!

–Michael
