using loop with a 'when'

I would like for ‘when’ to take the item to evaluate from the loop. How do i do it? Is it even possible?

You have 'item' as the representation of the 'current item in the
loop', but you are doing an indirection by 'letter' being the name of
a variable, the 'vars' lookup can resolve that, so you end up with:

when: lookup('vars', item['letter']) == True

It’s ugly but worked like a charm. Thank you very much.

You could use this if that look better

   when: vars[item.letter] == True

And since the value is True or False you could also just do this

   when: vars[item.letter]

You could use this if that look better

when: vars[item.letter] == True

Thank you for that. Now it’s working AND it’s pretty. Where is this documented? The lookup is “kind of” documented, though not anywhere near ‘loop’. So it would never have occurred to me to connect the two.

And since the value is True or False you could also just do this

when: vars[item.letter]

As I said originally, this was just an oversimplified example. The real playbook has more values than just boolean true/false.

vars is only documented one place, in the FAQ
https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#when-should-i-use-also-how-to-interpolate-variables-or-dynamic-variable-names

"if you need to use a dynamic variable use the hostvars or vars dictionary as appropriate"

vars is the same as hostvars[inventory_hostname]

No, don't use vars[varname], it is NOT the same as hostvars, it
includes vars not present in hostvars and it does not template the
variables in the same way. It is undocumented for a reason, it is not
meant for users, it was used internally (not anymore) and it is
scheduled for removal.

You CAN use the 'vars' lookup, i. e lookup('vars', 'varname') to deal
with dynamic variables, this also includes non host specific variables
not present in hostvars