multiple when_ conditionals

I was trying out using multiple when_conditionals

for example:

when_integer: $register.rc == 1
when_set: $myvalues

Should these work as an AND to determine if the action should run?

I was trying them out on 1.0 and it seemed like if the second one
defined was true then the action was run.

Any thoughts on how to do multiple conditions?

thanks,
-sv

IMHO this should be made to work as if they were all ANDed together.
It doesn't seem to read any other way .. at least to me.

That being said, when I built it, I didn't see them all being used to
together, but it totally makes sense that it should be possible.

I'm ok with changing the way this works as we never really definined
the meaning and I doubt many people are using them together.

I suspect what happens right now is they are overriding the
conditional with whatever was last in the argument hash order.

Right now to achieve the same results I have to do this monstrosity:

only_if: 'is_set("${volumes}") and "${host_is_up.rc}" != "0"'

Just in case you were looking for horribly unreadable things.

turning that into
when_failed: $host_is_up
when_set: $volumes

would just be fantastic.

-sv

IMHO this should be made to work as if they were all ANDed together.
It doesn't seem to read any other way .. at least to me.

That being said, when I built it, I didn't see them all being used to
together, but it totally makes sense that it should be possible.

I'm ok with changing the way this works as we never really definined
the meaning and I doubt many people are using them together.

I suspect what happens right now is they are overriding the
conditional with whatever was last in the argument hash order.

> I was trying out using multiple when_conditionals
>
> for example:
>
> when_integer: $register.rc == 1
> when_set: $myvalues

Right now to achieve the same results I have to do this monstrosity:

only_if: 'is_set("${volumes}") and "${host_is_up.rc}" != "0"'

Just in case you were looking for horribly unreadable things.

turning that into
when_failed: $host_is_up
when_set: $volumes

would just be fantastic.

right, please file a ticket if you haven't already :slight_smile:

I’ve tested this and it doesn’t work (i.e. it seemed to ignore the second & subsequent when__
I was aiming to post this a few days ago, then decided that I had a reasonable enough workaround in my specific case by using is_set and when_boolean

An AND will be better, but still won’t be general, in my case I needed an OR.

I've tested this and it *doesn't* work (i.e. it seemed to ignore the second
& subsequent when__
I was aiming to post this a few days ago, then decided that I had a
reasonable enough workaround in my specific case by using is_set and
when_boolean

Yeah, we know it doesn't work -- that's what we were saying earlier.

If you need an or, I'd just go with the "only_if" in that case. The
"and" seems like it would
be the "do what I mean" case at least for 80% of everyone out there.

- modulename: bar=12345
  register: foo

- modulename: asdf=1234
  when_changed: foo
  when_string: ${ansible_distribution} == 'CentOS'

etc