Inventory: support list of vars in host.
This commit is contained in:
parent
b5f6558872
commit
3b40158961
3 changed files with 17 additions and 2 deletions
|
@ -63,7 +63,12 @@ class InventoryParserYaml(object):
|
|||
|
||||
elif type(item) == dict and 'host' in item:
|
||||
host = self._make_host(item['host'])
|
||||
for (k,v) in item.get('vars',{}).items():
|
||||
vars = item.get('vars', {})
|
||||
if type(vars)==list:
|
||||
varlist, vars = vars, {}
|
||||
for subitem in varlist:
|
||||
vars.update(subitem)
|
||||
for (k,v) in vars.items():
|
||||
host.set_variable(k,v)
|
||||
|
||||
elif type(item) == dict and 'group' in item:
|
||||
|
|
|
@ -258,6 +258,14 @@ class TestInventory(unittest.TestCase):
|
|||
'hammer':True,
|
||||
'inventory_hostname': 'thor'}
|
||||
|
||||
def test_yaml_list_vars(self):
|
||||
inventory = self.yaml_inventory()
|
||||
vars = inventory.get_variables('zeus')
|
||||
assert vars == {'ansible_ssh_port': 3001,
|
||||
'group_names': ['greek', 'ruler'],
|
||||
'inventory_hostname': 'zeus',
|
||||
'ntp_server': 'olympus.example.com'}
|
||||
|
||||
def test_yaml_change_vars(self):
|
||||
inventory = self.yaml_inventory()
|
||||
vars = inventory.get_variables('thor')
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
moon: titan
|
||||
moon2: enceladus
|
||||
|
||||
- zeus
|
||||
- host: zeus
|
||||
vars:
|
||||
- ansible_ssh_port: 3001
|
||||
|
||||
- group: greek
|
||||
hosts:
|
||||
|
|
Loading…
Reference in a new issue