mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixed Inventory.get_hosts() ignoring restriction when there are no hosts left.
get_hosts() was treating [] (meaning complete restriction, no hosts allowed) the same as None (meaning no restriction, all hosts allowed). Fixed logic.
This commit is contained in:
parent
af9651f015
commit
81591009ea
1 changed files with 3 additions and 2 deletions
|
@ -89,9 +89,10 @@ class Inventory(object):
|
||||||
for host in group.get_hosts():
|
for host in group.get_hosts():
|
||||||
for pat in patterns:
|
for pat in patterns:
|
||||||
if group.name == pat or pat == 'all' or self._match(host.name, pat):
|
if group.name == pat or pat == 'all' or self._match(host.name, pat):
|
||||||
if not self._restriction:
|
#must test explicitly for None because [] means no hosts allowed
|
||||||
|
if self._restriction==None:
|
||||||
hosts[host.name] = host
|
hosts[host.name] = host
|
||||||
if self._restriction and host.name in self._restriction:
|
elif host.name in self._restriction:
|
||||||
hosts[host.name] = host
|
hosts[host.name] = host
|
||||||
return sorted(hosts.values(), key=lambda x: x.name)
|
return sorted(hosts.values(), key=lambda x: x.name)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue