Output from previous action

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

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.

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’”

    - name: Restart tomcat server
      action: service name=${tomcat_version} state=restarted
      only_if: '"${output.changed}'"

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