Testing if nested variable is defined

Assume the following variable structure:

`

vars:
foo:
bar:
baz: 5

`

If I simply to:

when: foo.bar.baz is defined

this only checks the baz key. I still get a failure if e.g. foo.bar is not defined. (The error was: error while evaluating conditional (foo.bar.baz is defined): ‘dict object’ has no attribute ‘bar’)

The proper way seems to be:

`

  • when:
  • foo is defined
  • foo.bar is defined
  • foo.bar.baz is defined

`

which is kind of verbose. Is there a better / more concise way of checking the entire foo.bar.baz chain?