mirror of
https://github.com/saltstack/salt-bootstrap.git
synced 2025-04-16 09:40:21 +00:00
Minimize python use when replacing configs
This commit is contained in:
parent
47d0308b8e
commit
3388e470b8
1 changed files with 3 additions and 6 deletions
|
@ -1901,17 +1901,14 @@ __overwriteconfig() {
|
|||
# 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
|
||||
|
||||
# Check if there were any errors output to the tempfile
|
||||
filesize=$(python -c "import os; print os.stat('$tempfile').st_size;")
|
||||
|
||||
# No python errors output to the tempfile
|
||||
if [ "$filesize" -eq 0 ]; then
|
||||
if [ ! -s "$tempfile" ]; then
|
||||
rm -f "$tempfile"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Errors are present in the tempfile - let's expose the that to the user.
|
||||
fullerror=$(python -c "tmp_file=open('$tempfile'); print tmp_file.read(); tmp_file.close()")
|
||||
# Errors are present in the tempfile - let's expose them to the user.
|
||||
fullerror=$(cat "$tempfile")
|
||||
echodebug "$fullerror"
|
||||
echoerror "Python error encountered. This is likely due to passing in a malformed JSON string. Please use -D to see stacktrace."
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue