@ -254,6 +254,28 @@ def parse_json(raw_data):
return { " failed " : True , " parsed " : False , " msg " : orig_data }
return { " failed " : True , " parsed " : False , " msg " : orig_data }
return results
return results
def preprocess_yaml ( data ) :
# allow the following casual user error:
# bar: {{ baz }}
# instead of bar: '{{ baz }}'
# (commander-API should auto-quote these in similar ways on save/load)
new_lines = [ ]
lines = data . split ( " \n " )
for line in lines :
if line . find ( " {{ " ) != - 1 and line . find ( " : " ) != - 1 :
tokens = line . split ( " : " , 1 )
if tokens [ 1 ] . strip ( ) . startswith ( " {{ " ) :
new_line = " %s : ' %s ' " % ( tokens [ 0 ] , tokens [ 1 ] )
else :
new_line = line
new_lines . append ( new_line )
else :
new_lines . append ( line )
result = " \n " . join ( new_lines )
return result
def parse_yaml ( data ) :
def parse_yaml ( data ) :
''' convert a yaml string to a data structure '''
''' convert a yaml string to a data structure '''
return yaml . safe_load ( data )
return yaml . safe_load ( data )
@ -288,6 +310,7 @@ def parse_yaml_from_file(path):
try :
try :
data = file ( path ) . read ( )
data = file ( path ) . read ( )
data = preprocess_yaml ( data )
return parse_yaml ( data )
return parse_yaml ( data )
except IOError :
except IOError :
raise errors . AnsibleError ( " file not found: %s " % path )
raise errors . AnsibleError ( " file not found: %s " % path )