Test python for yaml when replacing configs

This commit is contained in:
Ivan Kadochnikov 2016-09-13 03:35:20 +10:00
parent 3388e470b8
commit 7206d73043

View file

@ -1898,8 +1898,15 @@ __overwriteconfig() {
tempfile="/tmp/salt-config-$$"
fi
# If python does not have yaml installed we're on Arch and should use python2
if python -c "import yaml" 2> /dev/null; then
good_python=python
else
good_python=python2
fi
# Convert json string to a yaml string and write it to config file. Output is dumped into tempfile.
python -c "import json; import yaml; jsn=json.loads('$json'); yml=yaml.safe_dump(jsn, line_break='\n', default_flow_style=False); config_file=open('$target', 'w'); config_file.write(yml); config_file.close();" 2>$tempfile
$good_python -c "import json; import yaml; jsn=json.loads('$json'); yml=yaml.safe_dump(jsn, line_break='\n', default_flow_style=False); config_file=open('$target', 'w'); config_file.write(yml); config_file.close();" 2>$tempfile
# No python errors output to the tempfile
if [ ! -s "$tempfile" ]; then