Three and more conditions in playbook

68 views
Skip to first unread message

Сергей Антипов

unread,
Aug 15, 2014, 7:32:17 AM8/15/14
to ansible...@googlegroups.com
Hello.

This is possible to add more than 2 conditions like this?

- shell: ifdown {{ item.item.device }}; ifup {{ item.item.device }}
  with_items: ether_result.results
  when: ether_result is defined and and item.changed and ether_int_status|failed

ether_result and ether_int_status are registered variables.

Michael DeHaan

unread,
Aug 15, 2014, 9:18:36 AM8/15/14
to ansible...@googlegroups.com
Yes, this would also be easy for you to test and try on your own too :)

You can also do:

- shell: foo
  when:
     - a == b
     - c == d
     - e == f

And do ands that way, can sometimes be easier to read.
      


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9d1e3e8e-b758-42ce-bcd3-db617e0b52df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Сергей Антипов

unread,
Aug 18, 2014, 1:07:13 AM8/18/14
to ansible...@googlegroups.com
when: 
    - ether_result is defined
    - item|changed
    - ether_int_status|failed

This variant not work for me.
This works:
when: 
    - ether_result is defined
    - ether_int_status|failed

More than 2 conditions not work...((

пятница, 15 августа 2014 г., 20:18:36 UTC+7 пользователь Michael DeHaan написал:

Michael DeHaan

unread,
Aug 18, 2014, 8:31:30 AM8/18/14
to ansible...@googlegroups.com
"More than 2 conditions not work...(("

There's nothing in the code that has any bearing on how many conditions there are that makes 2 special, it's either "single" or "more than one"

That being said, if you can explain what "doesn't work" looks like and provide a minimal playbook with output, we can try to reproduce what you are seeing.

Thanks!




Сергей Антипов

unread,
Aug 18, 2014, 11:08:22 PM8/18/14
to ansible...@googlegroups.com
Thank you.

I found 2 errors in my code: 1 logical and 1 syntax.
Right conditions:

when: (ether_result is defined and ether_int_status is defined) and (ether_int_status|failed or ether_result.changed)

понедельник, 18 августа 2014 г., 19:31:30 UTC+7 пользователь Michael DeHaan написал:
Reply all
Reply to author
Forward
0 new messages