I see.
I think 'upper' should be used on a list using 'map':
- hosts: localhost
connection: local
gather_facts: no
vars:
environments:
- DEv
- UAt
- PrOd
tasks:
- fail:
msg: Your env '{{ env }}' was NOT found in environments
when: env|upper not in environments|map('upper')
~$ ansible-playbook work/tasks/list3.yml -e env=deV
[WARNING]: No inventory was parsed, only implicit localhost is available
PLAY [localhost]
*************************************************************************************************************
TASK [fail] ******************************************************************************************************************
skipping: [localhost]
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0
failed=0 skipped=1 rescued=0 ignored=0
And for substring it does not match:
~$ ansible-playbook work/tasks/list3.yml -e env=d
[WARNING]: No inventory was parsed, only implicit localhost is available
PLAY [localhost]
*************************************************************************************************************
TASK [fail] ******************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false
msg: Your env 'd' was NOT found in environments
PLAY RECAP *******************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0
failed=1 skipped=0 rescued=0 ignored=0
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/bc7ec796-652c-4357-ac60-ec4a397c5f3an%40googlegroups.com.