On Wednesday, February 1, 2023 at 2:42:33 PM UTC-5 [email protected] wrote:
Hi,
I just opened https://github.com/ansible/ansible/issues/79874 and Matt 
explained that 2.14 change is working as designed and closed the issue.

Matt put a link in the issue describing variable lazy eval and how 
undefined variables now work:
https://docs.ansible.com/ansible-core/2.14/porting_guides/porting_guide_core_2.14.html#playbook

I believe I'm tracking those changes, but I'm still lost on how my use case 
can be implemented.  My specific use case was a task's when clause 
determining to execute based on a top level variable being "authored".  If 
the author made a mistake in the nested elements, then an exception is 
desired.  How can this use case be implemented in 2.14?

You can use the varnames lookup to determine whether a top-level variable 
exists:
 
- name: Run when foo exists
  debug:
  when: query('varnames', '^foo$')

If you want to do a preflight check that the variable is defined properly, 
you can do something like this:

- assert:
    that: foo is defined
  when: query('varnames', '^foo$')

Then you can continue using `when: foo is defined` on your actual task(s), 
since you have asserted that the variable is either fully undefined or 
fully defined.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6d836e46-e3ae-466e-a463-57b02ac6fb6an%40googlegroups.com.

Reply via email to