# binding vars to the output of tasks/plays

**URL:** <https://forum.ansible.com/t/binding-vars-to-the-output-of-tasks-plays/11487>\
**Category:** Ansible Project\
**Created:** [May 2, 2012, 7:22am UTC](https://forum.ansible.com/t/binding-vars-to-the-output-of-tasks-plays/11487 "2012-05-02T07:22:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik\_Krishnamurth](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Karthik\_Krishnamurth](https://forum.ansible.com/u/Karthik_Krishnamurth)\
**Post date:** [May 2, 2012, 7:22am UTC](https://forum.ansible.com/t/binding-vars-to-the-output-of-tasks-plays/11487/1 "2012-05-02T07:22:06Z")

</div>

Hi,  
&nbsp;&nbsp;&nbsp;What i'm looking for specifically is to be able to do something  
like

tasks:  
&nbsp;&nbsp;- include: ec2/new\_instance.yml region=us-west2 env=staging  
&nbsp;&nbsp;- include apiserver/setup.yml instanceid=(the one setup above)  
&nbsp;&nbsp;- include apiserver/runtests.yml instanceid=(the one setup above)  
&nbsp;&nbsp;- include ec2/terminate\_instance.yml instanceid=(the one setup  
above)

IMO the ability for one task to inject variables back into the  
playbook would be immensely powerful.

Karthik

---

<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 2, 2012, 11:25am UTC](https://forum.ansible.com/t/binding-vars-to-the-output-of-tasks-plays/11487/2 "2012-05-02T11:25:29Z")

</div>

Tasks can actually do this, they just have to return a dictionary of ansible\_facts.

A patch to enable “last result” of some kind would not work well, because a given include statement could have many many tasks, and you also wouldn’t want to say  
“back up the stack N”.

A better idea is probably to have something like “save\_result\_as: varname”

- name: do stuff  
action: command /bin/whatever foo  
save\_result\_as: varname

- name: do other stuff  
action: command /bin/whatever foo {{ varname[“stout”] }}

(this being a variable saved in SETUP\_CACHE, most likely, and obviously usable in templates and not just action lines)

This would potentially be useful with things like only\_if, where you could run one command and then switch on the result.

If someone can get me a decently clean patch to do this, I think it’s a useful feature.
