# inconsistency regarding wildcards in inventory

**URL:** <https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559>\
**Category:** Ansible Project\
**Created:** [March 22, 2013, 10:56pm UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559 "2013-03-22T22:56:32Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [March 22, 2013, 10:56pm UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/1 "2013-03-22T22:56:32Z")

</div>

The doc ([http://ansible.cc/docs/patterns.html](http://ansible.cc/docs/patterns.html)) says:

"Individual host names (or IPs), but not groups, can also be referenced using wildcards:"

And sure enough this is the case in a plyabook, but, the command line ansible is happy to use wildcards on groups.

Two questions:  
-Why not supporting wildcards on groups?  
&nbsp;&nbsp;I suspect the issue a possible mix between groups and hostnames... but is this really a problem?

-shouldn't ansible and ansible-playbook be consistent?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 23, 2013, 1:12am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/2 "2013-03-23T01:12:29Z")

</div>

I'm actually not convinced what you say is true, seeing they use  
common inventory class.

I'd have to see an example.

---

<div class="post-metadata">

**Author:** ![Jim\_Richardson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jim\_Richardson](https://forum.ansible.com/u/Jim_Richardson)\
**Post date:** [March 23, 2013, 2:49am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/3 "2013-03-23T02:49:49Z")

</div>

I can verify this.

ansible corp-puppet\* --list-hosts returned the members of  
corp-puppetmaster group, a group in my inv script. The names of the  
servers in that group were not corp-puppet\*, they were varied.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [March 23, 2013, 3:31am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/4 "2013-03-23T03:31:48Z")

</div>

> I'm actually not convinced what you say is true, seeing they use  
> common inventory class.
> 
> I'd have to see an example.

Fair enough... It's not ansible, it's yaml!

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: \*proxies

Returns an error:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ERROR: Syntax Error while loading YAML script, x.yaml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note: The error may actually appear before this position: line 3, column 10

While both of these work fine (assuming the corresponding groups exist in $ANSIBLE\_HOSTS):

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: proxies\*

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: "\*proxies"

The doc says it shouldn't work:

\> "Individual host names (or IPs), but not groups, can also be referenced  
using wildcards:"

So now the question is do we fix the documentation or the behaviour (I vote for fixing the documentation!)?

---

<div class="post-metadata">

**Author:** ![Jim\_Richardson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jim\_Richardson](https://forum.ansible.com/u/Jim_Richardson)\
**Post date:** [March 23, 2013, 3:39am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/5 "2013-03-23T03:39:46Z")

</div>

jrichardson@jimmeh:~/repos/puppet\_etc/modules/puppet/manifests  
[master] $ ansible --version  
ansible 1.1  
jrichardson@jimmeh:~/repos/puppet\_etc/modules/puppet/manifests  
[master] $ cat \> /tmp/foo  
[foobar]  
host1  
host2  
host3  
[bar]  
host4  
jrichardson@jimmeh:~/repos/puppet\_etc/modules/puppet/manifests  
[master] $ ls foob\*  
ls: cannot access foob\*: No such file or directory  
jrichardson@jimmeh:~/repos/puppet\_etc/modules/puppet/manifests  
[master] $ ansible -i /tmp/foo foob\* --list-hosts  
&nbsp;&nbsp;&nbsp;&nbsp;host1  
&nbsp;&nbsp;&nbsp;&nbsp;host2  
&nbsp;&nbsp;&nbsp;&nbsp;host3

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [March 23, 2013, 4:21am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/6 "2013-03-23T04:21:35Z")

</div>

> jrichardson@jimmeh:~/repos/puppet\_etc/modules/puppet/manifests  
> [master] $ ansible -i /tmp/foo foob\* --list-hosts  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host1  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host2  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host3

Yes, the issue was yaml, I needed to quote the the pattern.

> > Fair enough... It's not ansible, it's yaml!
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: \*proxies
> > 
> > Returns an error:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ERROR: Syntax Error while loading YAML script, x.yaml  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Note: The error may actually appear before this position: line 3, column  
> > 10
> > 
> > While both of these work fine (assuming the corresponding groups exist in  
> > $ANSIBLE\_HOSTS):
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: proxies\*
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- hosts: "\*proxies"
> > 
> > The doc says it shouldn't work:
> > 
> > > "Individual host names (or IPs), but not groups, can also be referenced
> > 
> > using wildcards:"
> > 
> > So now the question is do we fix the documentation or the behaviour (I vote  
> > for fixing the documentation!)?

What I meant here is that what the doc says is not correct. it does work both with host names and groups. Should we fix the doc to reflect that?

Or is there any reason for wanting patterns not to work with groups (and therefor fix the behaviour)?

---

<div class="post-metadata">

**Author:** ![Jim\_Richardson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jim\_Richardson](https://forum.ansible.com/u/Jim_Richardson)\
**Post date:** [March 23, 2013, 4:52am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/7 "2013-03-23T04:52:01Z")

</div>

I like this behaviour, don't see any downsides. But maybe I am  
missing something.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [March 23, 2013, 5:10am UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/8 "2013-03-23T05:10:52Z")

</div>

Same here. I submitted a pull request with a change to the doc (it can't just be closed if there is a good reason to change the behaviour instead).

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [March 23, 2013, 3:30pm UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/9 "2013-03-23T15:30:37Z")

</div>

I am not certain groups should be wildcarded as it's a potential  
source of confusion.

---

<div class="post-metadata">

**Author:** ![Jim\_Richardson](https://avatars.discourse-cdn.com/v4/letter/j/d07c76/32.png) [@Jim\_Richardson](https://forum.ansible.com/u/Jim_Richardson)\
**Post date:** [March 23, 2013, 8:34pm UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/10 "2013-03-23T20:34:09Z")

</div>

I understand your concern there, but that really boils down to the  
admins not making confusing group names. The same issue already  
exists with sloppy wildcards. I'd use this feature as is, but if  
it's going to go away, I'll skip it 🙂

For me, it's a nice to have. But not a big deal either way.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [March 23, 2013, 9:13pm UTC](https://forum.ansible.com/t/inconsistency-regarding-wildcards-in-inventory/12559/11 "2013-03-23T21:13:39Z")

</div>

I don't know, I want to make sure we don't get into a case where a  
group name wildcard match is a problem.

That being said, I vaguely recall (misrecall) making group wildcard  
matching actually work.

Seeing you have to ask for it by saying "\*", I think maybe it's  
reasonable to leave as is and just tweak the docs after all.

I can't think of too many cases where it would be a problem now that I  
think about it, and it's never been a problem for me, anyway.
