0

I'm currently writing a ansible playbook with several conditions. I have a uri block with a when condition. The when condition checks if the var is defined and contains 0:

when: (logs_table_exist.stdout == "0") or ("0" in logs_table_old)

Now logs_table_exist will always have a value but logs_table_old can also be undefined. This when condition gives no error but it stays on false, even if logs_table_oldis 0.

Does anybody know how to fix this problem?

Thank you

Simon
  • 15
  • 3

1 Answers1

0

If there is any chance your variable might be undefined, use the default filter:

when: (logs_table_exist.stdout == "0") or ("0" in (logs_table_old | default([])))

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
  • thanks for your quick response. turns out i need to put .stdout to the logs_table_old and than it works. ```when: (logs_table_exist.stdout == "0") or ("0" in (logs_table_old.stdout | default([])))``` – Simon Dec 12 '19 at 12:27