mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow creating empty inventory
Instantiating the Inventory class with host_list=None now results in an empty inventory instead of an error.
This commit is contained in:
parent
776fc044dd
commit
d4dec5f577
2 changed files with 14 additions and 1 deletions
|
@ -70,7 +70,9 @@ class Inventory(object):
|
|||
host_list = host_list.split(",")
|
||||
host_list = [ h for h in host_list if h and h.strip() ]
|
||||
|
||||
if isinstance(host_list, list):
|
||||
if host_list is None:
|
||||
self.parser = None
|
||||
elif isinstance(host_list, list):
|
||||
self.parser = None
|
||||
all = Group('all')
|
||||
self.groups = [ all ]
|
||||
|
|
|
@ -30,6 +30,9 @@ class TestInventory(unittest.TestCase):
|
|||
print right
|
||||
assert left == right
|
||||
|
||||
def empty_inventory(self):
|
||||
return Inventory(None)
|
||||
|
||||
def simple_inventory(self):
|
||||
return Inventory(self.inventory_file)
|
||||
|
||||
|
@ -54,6 +57,14 @@ class TestInventory(unittest.TestCase):
|
|||
'Hotep-a', 'Hotep-b', 'Hotep-c',
|
||||
'BastC', 'BastD', ]
|
||||
|
||||
#####################################
|
||||
### Empty inventory format tests
|
||||
|
||||
def test_empty(self):
|
||||
inventory = self.empty_inventory()
|
||||
hosts = inventory.list_hosts()
|
||||
self.assertEqual(hosts, [])
|
||||
|
||||
#####################################
|
||||
### Simple inventory format tests
|
||||
|
||||
|
|
Loading…
Reference in a new issue