How do these differ?
when: query('varnames', '^foo$')
when: foo is defined
Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Feb 1, 2023, at 4:42 PM, flowerysong <[email protected]> wrote:
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<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.ansible.com%2Fansible-core%2F2.14%2Fporting_guides%2Fporting_guide_core_2.14.html%23playbook&data=05%7C01%7Cwalter.rowe%40nist.gov%7C1b49f9ef148e492dd58808db049d3f03%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638108845631513843%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=l%2BIgY1s79QnAjA9V%2FrlAkXMQCvhq8AowdrEJ0%2FLJ51w%3D&reserved=0>
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]<mailto:[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<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F6d836e46-e3ae-466e-a463-57b02ac6fb6an%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C1b49f9ef148e492dd58808db049d3f03%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638108845631513843%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=iyBrhjwb3dVaocDU0mgFLyb2azohir2FuD9mUP2I%2Bbo%3D&reserved=0>.
--
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/261108FA-252E-4AD4-AE3E-7F0B79230E4C%40nist.gov.