# Inventory pattern not matching in runbook

**URL:** <https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976>\
**Category:** Ansible Project\
**Created:** [December 5, 2014, 10:14pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976 "2014-12-05T22:14:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [December 5, 2014, 10:14pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976/1 "2014-12-05T22:14:16Z")

</div>

Hello,

I’ve got a simple inventory file setup and am using Ansible 1.8

`  
[tl-prod-mongo]  
tl-prod-mgdb-[01:06]

[tl-prod-web]  
tl-prod-aweb-[01:06]  
tl-prod-bweb-[01:06]  
tl-prod-cweb-[01:06]  
`

However, the following runbook fails to match any hosts

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 8, 2014, 5:27pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976/2 "2014-12-08T17:27:59Z")

</div>

try removing the - from the names, use \_ instead.

---

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [December 8, 2014, 9:37pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976/3 "2014-12-08T21:37:56Z")

</div>

Thanks, that works for the group names. But what if I’m just trying to specify 2 hosts inside a group of 6? Would I have to put them all in groups to get around this?

Is a - (dash) an invalid character for hostnames in Ansible? Or is it splitting on that somewhere when it shouldn’t be?

Jay

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 8, 2014, 9:46pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976/4 "2014-12-08T21:46:44Z")

</div>

the - is problematic with python dictionaries, which is what group  
names end up being, hosts should be fine.

list slices (hostgroup[:2]) should work

---

<div class="post-metadata">

**Author:** ![titleistfour](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@titleistfour](https://forum.ansible.com/u/titleistfour)\
**Post date:** [December 8, 2014, 10:16pm UTC](https://forum.ansible.com/t/inventory-pattern-not-matching-in-runbook/16976/5 "2014-12-08T22:16:11Z")

</div>

Well, when I try with hosts

ansible -m ping tl-prod-mgdb-[01:03]  
No hosts matched

ansible -m ping tl-prod-mgdb-[:03]  
No hosts matched

But…this works as long as I change the group name  
ansible -m ping tl\_prod\_mongo

Maybe the dash is problematic for hosts as well?

Jay
