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
The reason it works for you seems to be that you are not changing case for
environments.
This works:
---
- hosts: localhost
connection: local
gather_facts: no
vars:
environments:
- DeV
- Uat
- PROD
env: d
tasks:
- fail:
msg: Not a valid value
when: env|upper
No it doesn't. It works as you want.
(ansible-2.9.15) dick.visser@mbp ~$ ansible-playbook
work/tasks/list3.yml -e env=DEV
[WARNING]: No inventory was parsed, only implicit localhost is available
PLAY [localhost] ***
TASK [fail] ***
You have env: Acceptance in there but if you had it DEV or UAT or PROD,
it would have worked. I mean If you use DEV or UAT or PROD as value of
env, then it's all good which is fine. The problem is when the value of env
is just D (first letter of DEV) ie env: D, it still matches DEV.
On Mon,
On Mon, 25 Jan 2021 at 14:54, PluftPlayzRoblox wrote:
>
> Trying this:
>
> vars:
> environments: ['DEV Managed, UAT in the datacenter, PROD (in the cloud
> and data center)’]
As I've explained this is incorrect and does not mean what you think it means.
>env: NA
>
> tasks:
> - fail: ms
Trying this:
vars:
environments: ['DEV Managed, UAT in the datacenter, PROD (in the cloud
and data center)’]
env: NA
tasks:
- fail: msg="Not valid value"
when: env |upper not in environments |upper
and with the yaml list, esult is the same, NA matched Managed.
What I found is that if
Your environments variable definition seems to be incorrectly quoted so I'm
not even sure what that list looks like now.
You can also try the yaml list syntax:
environments:
- DEV Managed
- UAT somewhere else
- PROD blah
Also you compare 'version' but your example mentions 'env' (which is also
This matches even when part of the version is in an element of
environments, eg
vars:
environments: ['DEV Managed, UAT in the datacenter, PROD in the cloud
and data center]
env: NA
tasks:
- fail: msg="Not valid value"
when: version|upper not in environments |upper
As NA is in Mana
when: version|upper not in environments
On Fri, Jan 22, 2021 at 9:53 AM PluftPlayzRoblox
wrote:
>
> Trying to validate that a specific variable must have one of
> pre-determined values, mimicking dropdown in survey in ansible tower/awx.
>
> I have the following code but it only matches for upper
Trying to validate that a specific variable must have one of pre-determined
values, mimicking dropdown in survey in ansible tower/awx.
I have the following code but it only matches for upper case:
vars:
environments: [DEV, UAT, PROD]
env: DEV
tasks:
- fail: msg="Not valid value"
w
10 matches
Mail list logo