ansible --list-hosts behaviour is something strange, at least it works as i don’t expect, it differs from ansible 2.3 to ansible 2.4
test case:
created inventory
`
[group]
host1-c1
host2
[group1-c1]
host3
host4
[group2-c1]
host5
host6
host11-c1
`
2.3 ansible behaviour is to return all hosts and groups
`
ansible–list-hosts “*c1”
hosts (6):
host11-c1
host1-c1
host5
host6
host3
host4
`
2.4 ansible behaviour is to return hosts in groups if some group matches *c1 and if no match to group then return hosts
`
hosts (5):
host5
host6
host11-c1
host3
host4
`
and if i add “*1-c1” to parameter:
2.3 ansible:
`
ansible -i i --list-hosts “*1-c1”
hosts (4):
host11-c1
host1-c1
host3
host4
`
2.4 ansible:
ansible -i i --list-hosts "*1-c1"
hosts (2):
host3
host4
There is no consistency from version to version, and now i’m confused how it should be correctly. My version is that it should only return hosts in groups that match that expression, but what if i add one more symbol to expression “11-c1” both return just host, even there are no group which ends with 11-c1.
when i add such expression i should not be aware of matching hosts/groups if it returns hosts from groups, then this is fail, if it’s return all matches in groups and hosts then it’s fail again. When i add expression i cannot guarantee that someone else is not added some host with that match, or there is no more such group and i execute on some host which matches that expression not group.
so can someone explain the behaviour i observer and provide correct answer how it should work and how we can rely on this.