Below is my call ansible shell script shared by my colleague. I am trying to pass a user input variable feom jenkins pipeline to ansible template but unable to do so.
print frequency param of debugging
frequency = “$1”
echo “Freq : $frequency”
#pass template id and ansible url for use
templateId = 122807
ansibleurl = “https://stage-ansible-tower”
#make api call to launch job template and capture response id
echo “00000000000”
response_id = (curl -f -s -k -H 'Content-Type: application/json' -d "{}" --user {uname}:{passwd} -X POST https://stage-ansible-tower/api/v2/job_templates/{templateId}/launch/)
| python -c “import json,sys;obj=json.load(sys.stdin);print obj[‘job’];”)
#print response id for debugging
echo $response_id
#print response id to a file
echo $response_id > ansible_deployment_id.txt
echo “qqqqqqqqqqq”
#get initial status of the job
status1 = (curl -f -s -k -H 'Content-Type: application/xml' --user {uname}:${passwd} -X GET https://stage-ansible-tower/api/v2/jobs/$response_id/ | python -c “import json,sys;obj=json.load(sys.stdin);print obj[‘status’];”)
#print initial status for debugging
echo $status1
#wait until job status is either successful or failed
NEXT_WAIT_TIME=0
until [ “$status1” == “successful” ] || [ “$status1” == “failed” ]
do
echo "current status is status1"
#sleep (( NEXT_WAIT_TIME++ ))
sleep 5
status1=$(curl -f -s -k -H ‘Content-Type: application/xml’ --user /$response_id/ | python -c “import json,sys;obj=json.load(sys.stdin);print obj[‘status’];”)
done
if [ “$status1” == “successful” ]
then
echo “ansible job execution is passed, please check log at $ansibleurl/#/jobs/$response_id/”
else
echo “ansible job execution failed, please check log at $ansibleurl/#/jobs/$response_id/”
exit 1
fi