conditional with register in one task?

Hi,

should this work:

   tasks:
   - name: test
     shell: uname -a
     when: env == "test"

   - name: test 1
     file: path=/opt/test.txt state=touch
     when: env == "test1"
     register: test_1

   - name: test 2
     file: path=/opt/test2 state=touch
     when: test_1 is defined

Task "test 1" should run, if some conditional is true.
Depending on if it runs, task "test 2" should run.
That's why i registered a variable test_1.

The result is, that "test 1" ist skipped", because env != "test" (as expected; OK). But "test 2" does run too.

I could use a handler, but that does only run after all the tasks, which why I have to change the running order. Is there another way?

Marc

Even though a task is skipped, the registered variable is still created. You would want to check something like the following on your “test 2” task instead:

when: not test_1|skipped

Matt,

Matt Martz schrieb (11.03.2015 16:08 Uhr):

Even though a task is skipped, the registered variable is still created. You would want to check something like the following on your "test 2" task instead:

when: not test_1|skipped

this works, thank you!

The docs could be a bit clearer about this part.
http://docs.ansible.com/playbooks_conditionals.html does not explain what "result|skipped" exactly means.

Marc