Whenever a ternary is used are both conditions evaluated regardless ? 

For example, I want to convert "my_other_var" to an object only if it is 
passed as as string, otherwise I don't want to touch the object, and leave 
it as it is.

- set_fact:
    my_var: "{{  ( my_other_var | type_debug == 'str' ) | ternary 
(my_other_var | from_json, my_other_var }}"

What happens right now is this:

if my_other_var is str -> It works
if my_other_var is dict -> it gives me the error saying that my_other_var 
should be a string to be converted from_json. But I would expect that being 
the condition on the left = False, it would ignore the left condition on 
the ternary and only consider the rightmost condition.

I also tried using when:

-- name: Set fact for string  object
     my_var: "{{ my_other_var | from_json }}"
  when: (my_other_var | type_debug == 'str')

- name: Set fat for dict  object
    my_var: "{{ my_other_var | from_json }}"
  when: (my_other_var | type_debug == 'dict')

However, if "my_other_var" is dict, the first block (named set fact for 
string object) gives me the same error as before. I was actually expecting 
that being the when statement equals to false, it would simply ignore it.

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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Reply via email to