Skip to content

Commit

Permalink
Merge pull request #95 from ody/fix_failures_with_exit
Browse files Browse the repository at this point in the history
Revert "made print() call Py3 compliant, added checks for Py execs"
  • Loading branch information
reidmv committed May 15, 2020
2 parents ae9ec67 + 4a1ea94 commit 6134727
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions tasks/read_file.json
Expand Up @@ -7,6 +7,7 @@
}
},
"implementations": [
{"name": "read_file.rb", "requirements": ["puppet-agent"], "input_method": "stdin"},
{"name": "read_file.sh", "requirements": ["shell"], "input_method": "environment"}
]
}
24 changes: 11 additions & 13 deletions tasks/read_file.sh
@@ -1,21 +1,10 @@
#!/bin/bash

main() {
local python_exec=""

# check if any python exec is available on the remote system. error out if not
while :; do
python_exec=$(command -v python) && break
python_exec=$(command -v python3) && break
python_exec=$(command -v python2) && break
echo "Error: No Python version 2 or 3 interpreter found."
exit 1
done

if [ -r "$PT_path" ]; then
cat <<-EOS
{
"content": $(${python_exec} -c "import json; print(json.dumps(open('$PT_path','r').read()))")
"content": $(python_cmd -c "import json; print json.dumps(open('$PT_path','r').read())")
}
EOS
else
Expand All @@ -25,8 +14,17 @@ main() {
"error": "File does not exist or is not readable"
}
EOS
exit 1
fi
}

python_cmd() {
if command -v python >/dev/null 2>&1; then
python "$@"
else
python3 "$@"
fi
}

main "$@"
exit_code=$?
exit $exit_code

0 comments on commit 6134727

Please sign in to comment.