# Output from previous action

**URL:** <https://forum.ansible.com/t/output-from-previous-action/11869>\
**Category:** Ansible Project\
**Created:** [September 7, 2012, 5:56am UTC](https://forum.ansible.com/t/output-from-previous-action/11869 "2012-09-07T05:56:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yerrysherry](https://avatars.discourse-cdn.com/v4/letter/y/b5e925/32.png) [@yerrysherry](https://forum.ansible.com/u/yerrysherry)\
**Post date:** [September 7, 2012, 5:56am UTC](https://forum.ansible.com/t/output-from-previous-action/11869/1 "2012-09-07T05:56:22Z")

</div>

Hey,

I have a task which copy a war file to a server:

- name: Copy snapshot war to server  
action: copy src=$gl\_base\_dir/$project/files/${reg\_nexus\_snapshot\_war.stdout} dest=$gl\_tomcat\_apps\_dir/${reg\_nexus\_snapshot\_war.stdout} owner=tomcat group=tomcat mode=0755

When running:

TASK: [Copy snapshot war to server] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
…  
ok: [server] =\> {“changed”: false, “group”: “tomcat”, “md5sum”: “ff143b67eabfb319767acd19649c9abc”, “mode”: “0755”, “owner”: “tomcat”, “path”: “/opt/tomcat/apps/mkros-web-3.9.2-20120704.075828-1.war”, “state”: “file”, “transferred”: false}

Is it possible to use this output in my next action, something like this

- name: Restart tomcat server  
action: service name=${tomcat\_version} state=restarted

only\_if: previous\_task. transferred = True

Regards,  
Gerrit

---

<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:** [September 7, 2012, 12:09pm UTC](https://forum.ansible.com/t/output-from-previous-action/11869/2 "2012-09-07T12:09:47Z")

</div>

You need to read up on the 'register' keyword and 'only\_if' on the  
Advanced Playbooks page of the docs.

only\_if takes a valid Python expression.

---

<div class="post-metadata">

**Author:** ![yerrysherry](https://avatars.discourse-cdn.com/v4/letter/y/b5e925/32.png) [@yerrysherry](https://forum.ansible.com/u/yerrysherry)\
**Post date:** [September 7, 2012, 2:21pm UTC](https://forum.ansible.com/t/output-from-previous-action/11869/3 "2012-09-07T14:21:28Z")

</div>

Ok, I understand this, but the module is “copy”

- name: Copy snapshot war to server  
action: copy src=$gl\_base\_dir/$project/files/${reg\_nexus\_snapshot\_war.stdout} dest=$gl\_tomcat\_apps\_dir/${reg\_nexus\_snapshot\_war.stdout} owner=tomcat group=tomcat mode=0755  
register: output

The output from this action is: (when running playbook with -vvv)

ok: [server] =\> {“changed”: false, “group”: “tomcat”, “md5sum”: “ff143b67eabfb319767acd19649c9abc”, “mode”: “0755”, “owner”: “tomcat”, “path”: “/opt/tomcat/apps/mkros-web-3.9.2-20120704.075828-1.war”, “state”: “file”, “transferred”: false}

- name: Restart tomcat server  
action: service name=${tomcat\_version} state=restarted

only\_if: ‘"${output.changed}’"

or an other example:

tasks:

- name: copy  
action: copy dest=/var/tmp/test.txt src=/var/tmp/test.txt  
register: output

- name: go  
action: command touch /var/tmp/gerrit  
only\_if: “‘${output.changed}’ == ‘true’”

---

<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:** [September 7, 2012, 2:38pm UTC](https://forum.ansible.com/t/output-from-previous-action/11869/4 "2012-09-07T14:38:43Z")

</div>

> &nbsp;&nbsp;&nbsp;&nbsp;- name: Restart tomcat server  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action: service name=${tomcat\_version} state=restarted  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;only\_if: '"${output.changed}'"

You're over thinking this one a bit -- Just use 'notify' and one or  
more handlers.
