# when list of strings NOT IN hostname

**URL:** <https://forum.ansible.com/t/when-list-of-strings-not-in-hostname/18902>\
**Category:** Ansible Project\
**Created:** [July 30, 2015, 2:19pm UTC](https://forum.ansible.com/t/when-list-of-strings-not-in-hostname/18902 "2015-07-30T14:19:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [July 30, 2015, 2:19pm UTC](https://forum.ansible.com/t/when-list-of-strings-not-in-hostname/18902/1 "2015-07-30T14:19:54Z")

</div>

I’m trying to get a configuration deployed to a large group of hosts except for a few specific ones. I am trying very hard to not use an inventory group to manage this. I’ve tried a few different methods and cannot seem to get it to work. Here are examples of what I’ve tried:

when: ‘“abc”:“def”:“ghi” not in inventory\_hostname’

when: ‘“[abc, def, ghi]” not in inventory\_hostname’

when: ‘“{{ item }}” not in inventory\_hostname’  
with\_items:

- abc
- def
- ghi

Thoughts?

---

<div class="post-metadata">

**Author:** ![Timothy\_Gerla](https://avatars.discourse-cdn.com/v4/letter/t/977dab/32.png) [@Timothy\_Gerla](https://forum.ansible.com/u/Timothy_Gerla)\
**Post date:** [July 30, 2015, 2:21pm UTC](https://forum.ansible.com/t/when-list-of-strings-not-in-hostname/18902/2 "2015-07-30T14:21:53Z")

</div>

I am not sure why you would be avoiding inventory groups, since they’re built for this purpose…but you probably want:

when: “abc” not in inventory\_hostname and “def” not in inventory\_hostname and “ghi” not in inventory\_hostname

-Tim

---

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [July 30, 2015, 2:25pm UTC](https://forum.ansible.com/t/when-list-of-strings-not-in-hostname/18902/3 "2015-07-30T14:25:45Z")

</div>

Thanks, Tim that is very helpful. I have a ton of groups already and am trying to minimize them and not pile on.

I could do this with host\_vars (since it is lines in configuration files that are different). I didn’t think of that until I read your response so I definitely am thankful.
