# not able to match a string in a var list.

**URL:** <https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012>\
**Category:** Ansible Project\
**Created:** [March 30, 2016, 2:48am UTC](https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012 "2016-03-30T02:48:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 30, 2016, 2:48am UTC](https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012/1 "2016-03-30T02:48:50Z")

</div>

Hi All

Doing something Im sure seems odd but building a production deployment script based on some very manual steps. The dev team list out all the services that need to be upgraded. I made a var called deploy to do two things.

1. Write out to a build file what needs to be build for prod. Its a flat file
2. Be able to include upgrade tasks based on if api or data appears in the deployment list

Example of my variable

var:  
deploy:

- api-app v2.41.0
- api-develop v0.23.2
- api-tool v0.24.0
- api-consumers v0.16.0
- api-data v0.57.2
- api-bus eventbus-v1.1.2

Im trying to do the following.

- include task/upgrade-api.yml  
when: “‘api’ in deploy”

This does not work as for some reason as Ive put spaces between it im thinking it cant seem to find ‘api’ at all. If I change the deploy var and remove the versions and have it as one liners like below, it will find a match if I was to have when: “’ api-too’ in deploy. It seems to want to match a whole line and not part of it. I tried doing when: deploy |search(“api’”) but it failed because I think its a list. Im sure there is a better way to do this but wondering why my 'api in deploy” is not finding a match.

var:  
deploy:

- api-app
- api-develop
- api-tool
- api-consumers
- api-data
- api-bus

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [March 30, 2016, 4:14am UTC](https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012/2 "2016-03-30T04:14:06Z")

</div>

Using minus or "." in a variable is very, very bad idea... Like in  
python those are functions  
Try using underscore instead  
So :  
api-app =\> api\_app  
api-develop =\> api\_develop  
...

Regards,

---

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 30, 2016, 5:01am UTC](https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012/3 "2016-03-30T05:01:41Z")

</div>

Thanks Jean

But the issue is that even when I changed them to underscore (like below), Im finding when I do the “‘api’ in deploy” it seems to not find it. Its only when Its a completely match in a line it works. ie when: “‘api\_author’ in deploy”.

Example (this does not work)

deploy:

- api\_assess

- api\_author

- include: tasks/update-api.yml

when: “‘api’ in deploy”

Example (this works)

deploy:

- api\_assess

- api\_author

- include: tasks/update-api.yml

when: “‘api\_assess’ in deploy”

😕

---

<div class="post-metadata">

**Author:** ![Uditha\_Desilva](https://avatars.discourse-cdn.com/v4/letter/u/f475e1/32.png) [@Uditha\_Desilva](https://forum.ansible.com/u/Uditha_Desilva)\
**Post date:** [March 30, 2016, 10:43pm UTC](https://forum.ansible.com/t/not-able-to-match-a-string-in-a-var-list/21012/4 "2016-03-30T22:43:14Z")

</div>

Looks to me like you’re actually building a dict of dicts, rather than a simple list. For example, this works for me:
