Skip to content

Commit

Permalink
InventoryScript: better syntax checking for json stream
Browse files Browse the repository at this point in the history
  • Loading branch information
srgvg committed Aug 21, 2014
1 parent b8d0572 commit 3a228b9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ansible/inventory/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ def _parse(self, err):

if not isinstance(data, dict):
data = {'hosts': data}
# is not those subkeys, then simplified syntax, host with vars
elif not any(k in data for k in ('hosts','vars')):
data = {'hosts': [group_name], 'vars': data}

if 'hosts' in data:
if not isinstance(data['hosts'], list):
raise errors.AnsibleError("You defined a group \"%s\" with bad "
"data for the host list:\n %s" % (group_name, data))

for hostname in data['hosts']:
if not hostname in all_hosts:
Expand All @@ -96,6 +100,10 @@ def _parse(self, err):
group.add_host(host)

if 'vars' in data:
if not isinstance(data['vars'], dict):
raise errors.AnsibleError("You defined a group \"%s\" with bad "
"data for variables:\n %s" % (group_name, data))

for k, v in data['vars'].iteritems():
if group.name == all.name:
all.set_variable(k, v)
Expand Down

0 comments on commit 3a228b9

Please sign in to comment.