diff --git a/tasks/read_file.json b/tasks/read_file.json index 3c7a3f76..882da936 100644 --- a/tasks/read_file.json +++ b/tasks/read_file.json @@ -7,7 +7,6 @@ } }, "implementations": [ - {"name": "read_file.rb", "requirements": ["puppet-agent"], "input_method": "stdin"}, {"name": "read_file.sh", "requirements": ["shell"], "input_method": "environment"} ] } diff --git a/tasks/read_file.sh b/tasks/read_file.sh index 208b0eb2..6039d8ea 100755 --- a/tasks/read_file.sh +++ b/tasks/read_file.sh @@ -1,10 +1,21 @@ #!/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_cmd -c "import json; print json.dumps(open('$PT_path','r').read())") + "content": $(${python_exec} -c "import json; print(json.dumps(open('$PT_path','r').read()))") } EOS else @@ -14,17 +25,8 @@ main() { "error": "File does not exist or is not readable" } EOS - fi -} - -python_cmd() { - if command -v python >/dev/null 2>&1; then - python "$@" - else - python3 "$@" + exit 1 fi } main "$@" -exit_code=$? -exit $exit_code