Merge branch 'align-vars-syntax' of https://github.com/jhoekx/ansible into jhoekx-align-vars-syntax
This commit is contained in:
commit
8a433ecb96
4 changed files with 26 additions and 9 deletions
|
@ -216,11 +216,16 @@ class Inventory(object):
|
||||||
|
|
||||||
def _parse_yaml_host(self, item, variables=[]):
|
def _parse_yaml_host(self, item, variables=[]):
|
||||||
def set_variables(host, variables):
|
def set_variables(host, variables):
|
||||||
for variable in variables:
|
if type(variables) == list:
|
||||||
if len(variable) != 1:
|
for variable in variables:
|
||||||
raise errors.AnsibleError("Only one item expected in %s"%(variable))
|
if len(variable) != 1:
|
||||||
k, v = variable.items()[0]
|
raise errors.AnsibleError("Only one item expected in %s"%(variable))
|
||||||
self._set_variable(host, k, v)
|
k, v = variable.items()[0]
|
||||||
|
self._set_variable(host, k, v)
|
||||||
|
elif type(variables) == dict:
|
||||||
|
for k, v in variables.iteritems():
|
||||||
|
self._set_variable(host, k, v)
|
||||||
|
|
||||||
|
|
||||||
if type(item) in [str, unicode]:
|
if type(item) in [str, unicode]:
|
||||||
set_variables(item, variables)
|
set_variables(item, variables)
|
||||||
|
|
|
@ -118,8 +118,18 @@ class PlayBook(object):
|
||||||
if play.get('vars') is None:
|
if play.get('vars') is None:
|
||||||
play['vars'] = {}
|
play['vars'] = {}
|
||||||
vars = play['vars']
|
vars = play['vars']
|
||||||
if type(vars) != dict:
|
if type(vars) not in [dict, list]:
|
||||||
raise errors.AnsibleError("'vars' section must contain only key/value pairs")
|
raise errors.AnsibleError("'vars' section must contain only key/value pairs")
|
||||||
|
|
||||||
|
# translate a list of vars into a dict
|
||||||
|
if type(vars) == list:
|
||||||
|
varlist = vars
|
||||||
|
vars = {}
|
||||||
|
for item in varlist:
|
||||||
|
k, v = item.items()[0]
|
||||||
|
vars[k] = v
|
||||||
|
play['vars'] = vars
|
||||||
|
|
||||||
vars_prompt = play.get('vars_prompt', {})
|
vars_prompt = play.get('vars_prompt', {})
|
||||||
if type(vars_prompt) != dict:
|
if type(vars_prompt) != dict:
|
||||||
raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs")
|
raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs")
|
||||||
|
|
|
@ -220,13 +220,13 @@ class TestInventory(unittest.TestCase):
|
||||||
inventory = self.yaml_inventory()
|
inventory = self.yaml_inventory()
|
||||||
vars = inventory.get_variables('saturn')
|
vars = inventory.get_variables('saturn')
|
||||||
|
|
||||||
assert vars == {"moon":"titan"}
|
assert vars == {"moon":"titan", "moon2":"enceladus"}
|
||||||
|
|
||||||
def test_yaml_port(self):
|
def test_yaml_port(self):
|
||||||
inventory = self.yaml_inventory()
|
inventory = self.yaml_inventory()
|
||||||
vars = inventory.get_variables('hera')
|
vars = inventory.get_variables('hera')
|
||||||
|
|
||||||
assert vars == {'ansible_ssh_port': 3000}
|
assert vars == {'ansible_ssh_port': 3000, 'ntp_server': 'olympus.example.com'}
|
||||||
|
|
||||||
### Test Runner class method
|
### Test Runner class method
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
- jupiter
|
- jupiter
|
||||||
- host: saturn
|
- host: saturn
|
||||||
vars:
|
vars:
|
||||||
- moon: titan
|
moon: titan
|
||||||
|
moon2: enceladus
|
||||||
|
|
||||||
- zeus
|
- zeus
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
- poseidon
|
- poseidon
|
||||||
vars:
|
vars:
|
||||||
- ansible_ssh_port: 3000
|
- ansible_ssh_port: 3000
|
||||||
|
- ntp_server: olympus.example.com
|
||||||
|
|
||||||
- group: norse
|
- group: norse
|
||||||
hosts:
|
hosts:
|
||||||
|
|
Loading…
Reference in a new issue