# Lookup variable strange behaviour

**URL:** <https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [February 16, 2013, 8:55pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368 "2013-02-16T20:55:50Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [February 16, 2013, 8:55pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/1 "2013-02-16T20:55:50Z")

</div>

This is fixed in Ansible's 1.1 development branch.

The workaround for anyone who does not yet want to upgrade, is to  
upgrade, but failing that, you can use the "with\_file" or "with\_env"  
version instead and just reference the array when you use it.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Paczkowski](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tomasz\_Paczkowski](https://forum.ansible.com/u/Tomasz_Paczkowski)\
**Post date:** [February 17, 2013, 1:34pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/2 "2013-02-17T13:34:58Z")

</div>

Thanks for help.  
Is evaluating $LOOKUP again on every use of the variable holding it part of this?  
The date keeps changing, quite annoyingly.

---

<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:** [February 17, 2013, 2:19pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/3 "2013-02-17T14:19:20Z")

</div>

Evaluation is meant to be lazy.

We can pretty easily make an option to cache.

Can you file a github ticket so we don't forget?

Assume you are using $PIPE ?

Thanks!

---

<div class="post-metadata">

**Author:** ![Tomasz\_Paczkowski](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tomasz\_Paczkowski](https://forum.ansible.com/u/Tomasz_Paczkowski)\
**Post date:** [February 17, 2013, 2:27pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/4 "2013-02-17T14:27:38Z")

</div>

Here it goes: [https://github.com/ansible/ansible/issues/2108](https://github.com/ansible/ansible/issues/2108)

Again thanks for help!  
BTW Ansible rocks.

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [February 17, 2013, 4:23pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/5 "2013-02-17T16:23:44Z")

</div>

+1, great feature.

Tomek,

This is what we currently do (you could use this as a workaround until the  
feature lands):

&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;- name: get the current time for a timestamp  
&nbsp;&nbsp;&nbsp;&nbsp;local\_action: command date +%Y%m%d-%H%M%S  
&nbsp;&nbsp;&nbsp;&nbsp;register: time

Then we use ${time.stdout} where we need the timestamp variable.

Take care,

Lorin

---

<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:** [February 17, 2013, 4:31pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/6 "2013-02-17T16:31:48Z")

</div>

> &nbsp;&nbsp;tasks:  
> &nbsp;&nbsp;- name: get the current time for a timestamp  
> &nbsp;&nbsp;&nbsp;&nbsp;local\_action: command date +%Y%m%d-%H%M%S  
> &nbsp;&nbsp;&nbsp;&nbsp;register: time

Good idea.

This will still result in a different time per node, but not if you  
select the time from a particular host via hostvars.

Give me an hour, but it should be less. Set your stopwatches 🙂

---

<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:** [February 17, 2013, 4:44pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/7 "2013-02-17T16:44:07Z")

</div>

Done, here's my test playbook. I'm not sure i'm crazy about this  
useful cache logic not being accessible to ALL lookup plugins, so we  
may generalize the "with\_\*\_once" behavior later so the caching is done  
at a higher level.

I'll file a ticket to do so, though this works now and we'll keep this syntax.

My watch says 11 minutes 🙂

--Michael

---

<div class="post-metadata">

**Author:** ![Tomasz\_Paczkowski](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tomasz\_Paczkowski](https://forum.ansible.com/u/Tomasz_Paczkowski)\
**Post date:** [February 17, 2013, 5:27pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/8 "2013-02-17T17:27:36Z")

</div>

That was fast. I went out for dinner and came back to see this done.

It works like charm now. Kudos to you Michael.

Once again thanks for help!

---

<div class="post-metadata">

**Author:** ![Tomasz\_Paczkowski](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@Tomasz\_Paczkowski](https://forum.ansible.com/u/Tomasz_Paczkowski)\
**Post date:** [February 17, 2013, 6:41pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/9 "2013-02-17T18:41:06Z")

</div>

I’ve found bug in this, please see comment on the github issue.

---

<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:** [February 17, 2013, 6:45pm UTC](https://forum.ansible.com/t/lookup-variable-strange-behaviour/12368/10 "2013-02-17T18:45:15Z")

</div>

Yeah, if tasks have names it doesn't quite work right. I'll figure  
it out, if others want to beat me to it, go ahead. Working on some  
other things first.
