|
|
|
@ -236,15 +236,7 @@ def parse_yaml(data):
|
|
|
|
|
''' convert a yaml string to a data structure '''
|
|
|
|
|
return yaml.load(data)
|
|
|
|
|
|
|
|
|
|
def parse_yaml_from_file(path):
|
|
|
|
|
''' convert a yaml file to a data structure '''
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
data = file(path).read()
|
|
|
|
|
return parse_yaml(data)
|
|
|
|
|
except IOError:
|
|
|
|
|
raise errors.AnsibleError("file not found: %s" % path)
|
|
|
|
|
except yaml.YAMLError, exc:
|
|
|
|
|
def process_yaml_error(exc, data, path=None):
|
|
|
|
|
if hasattr(exc, 'problem_mark'):
|
|
|
|
|
mark = exc.problem_mark
|
|
|
|
|
if mark.line -1 >= 0:
|
|
|
|
@ -262,9 +254,24 @@ Note: The error may actually appear before this position: line %s, column %s
|
|
|
|
|
else:
|
|
|
|
|
# No problem markers means we have to throw a generic
|
|
|
|
|
# "stuff messed up" type message. Sry bud.
|
|
|
|
|
if path:
|
|
|
|
|
msg = "Could not parse YAML. Check over %s again." % path
|
|
|
|
|
else:
|
|
|
|
|
msg = "Could not parse YAML."
|
|
|
|
|
raise errors.AnsibleYAMLValidationFailed(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_yaml_from_file(path):
|
|
|
|
|
''' convert a yaml file to a data structure '''
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
data = file(path).read()
|
|
|
|
|
return parse_yaml(data)
|
|
|
|
|
except IOError:
|
|
|
|
|
raise errors.AnsibleError("file not found: %s" % path)
|
|
|
|
|
except yaml.YAMLError, exc:
|
|
|
|
|
process_yaml_error(exc, data, path)
|
|
|
|
|
|
|
|
|
|
def parse_kv(args):
|
|
|
|
|
''' convert a string of key/value items to a dict '''
|
|
|
|
|
|
|
|
|
|