1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #1033 from jkleint/hosts-list-fix

Fix inventory.get_hosts when hosts is a list.
This commit is contained in:
Michael DeHaan 2012-09-11 14:55:18 -07:00
commit 522a3b5974
2 changed files with 11 additions and 1 deletions

View file

@ -97,6 +97,8 @@ class Inventory(object):
""" """
# process patterns # process patterns
if isinstance(pattern, list):
pattern = ';'.join(pattern)
patterns = pattern.replace(";",":").split(":") patterns = pattern.replace(";",":").split(":")
positive_patterns = [ p for p in patterns if not p.startswith("!") ] positive_patterns = [ p for p in patterns if not p.startswith("!") ]
negative_patterns = [ p for p in patterns if p.startswith("!") ] negative_patterns = [ p for p in patterns if p.startswith("!") ]

View file

@ -238,3 +238,11 @@ class TestInventory(unittest.TestCase):
'group_names': ['norse'], 'group_names': ['norse'],
'inventory_hostname': 'thor', 'inventory_hostname': 'thor',
'inventory_hostname_short': 'thor'} 'inventory_hostname_short': 'thor'}
def test_hosts_list(self):
"""Test the case when playbook 'hosts' var is a list."""
inventory = self.script_inventory()
host_names = sorted(['thor', 'loki', 'odin']) # Not sure if sorting is in the contract or not
actual_hosts = inventory.get_hosts(host_names)
actual_host_names = [host.name for host in actual_hosts]
assert host_names == actual_host_names