From 1f8696f5c17e3fc72a2968466072b24786f8b050 Mon Sep 17 00:00:00 2001 From: John Kleint Date: Tue, 11 Sep 2012 13:00:40 -0400 Subject: [PATCH] Fix inventory.get_hosts when hosts is a list. --- lib/ansible/inventory/__init__.py | 4 +++- test/TestInventory.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 6e83064f83..4026f86fa6 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -96,7 +96,9 @@ class Inventory(object): applied subsets. """ - # process patterns + # process patterns + if isinstance(pattern, list): + pattern = ';'.join(pattern) patterns = pattern.replace(";",":").split(":") positive_patterns = [ p for p in patterns if not p.startswith("!") ] negative_patterns = [ p for p in patterns if p.startswith("!") ] diff --git a/test/TestInventory.py b/test/TestInventory.py index ec71f54bc1..048126cc78 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -238,3 +238,11 @@ class TestInventory(unittest.TestCase): 'group_names': ['norse'], 'inventory_hostname': '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