|
|
@ -24,14 +24,10 @@ jobs:
|
|
|
|
echo "Modified folders: $folders"
|
|
|
|
echo "Modified folders: $folders"
|
|
|
|
echo "::set-output name=folders::$folders"
|
|
|
|
echo "::set-output name=folders::$folders"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Determine target host
|
|
|
|
- name: Deploy to hosts
|
|
|
|
id: determine-host
|
|
|
|
|
|
|
|
run: |
|
|
|
|
run: |
|
|
|
|
folder=$(echo "${{ steps.detect-changes.outputs.folders }}" | head -n 1)
|
|
|
|
IFS=' ' read -r -a folder_array <<< "${{ steps.detect-changes.outputs.folders }}"
|
|
|
|
if [ -z "$folder" ]; then
|
|
|
|
for folder in "${folder_array[@]}"; do
|
|
|
|
echo "No modified folders detected"
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
case $folder in
|
|
|
|
case $folder in
|
|
|
|
arrs)
|
|
|
|
arrs)
|
|
|
|
target_host="arrs.lan"
|
|
|
|
target_host="arrs.lan"
|
|
|
@ -78,37 +74,24 @@ jobs:
|
|
|
|
# Add cases for other folders/hosts
|
|
|
|
# Add cases for other folders/hosts
|
|
|
|
*)
|
|
|
|
*)
|
|
|
|
echo "Unknown folder: $folder"
|
|
|
|
echo "Unknown folder: $folder"
|
|
|
|
exit 1
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
esac
|
|
|
|
echo "::set-output name=target_host::$target_host"
|
|
|
|
echo "Triggering AWX Job with target host: $target_host and folder: $folder"
|
|
|
|
echo "::set-output name=folder::$folder"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Trigger AWX Job
|
|
|
|
|
|
|
|
run: |
|
|
|
|
|
|
|
|
TARGET_HOST="${{ steps.determine-host.outputs.target_host }}"
|
|
|
|
|
|
|
|
FOLDER="${{ steps.determine-host.outputs.folder }}"
|
|
|
|
|
|
|
|
echo "Triggering AWX Job with target host: $TARGET_HOST and folder: $FOLDER"
|
|
|
|
|
|
|
|
curl -X POST -k -H "Content-Type: application/json" \
|
|
|
|
curl -X POST -k -H "Content-Type: application/json" \
|
|
|
|
-H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
|
|
|
|
-H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" \
|
|
|
|
-d "{\"extra_vars\": {\"target_host\": \"$TARGET_HOST\", \"folder\": \"$FOLDER\"}}" \
|
|
|
|
-d "{\"extra_vars\": {\"target_host\": \"$target_host\", \"folder\": \"$folder\"}}" \
|
|
|
|
"https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/"
|
|
|
|
"https://awx.mafyuh.xyz/api/v2/job_templates/13/launch/"
|
|
|
|
|
|
|
|
|
|
|
|
- name: Delay for 45 seconds
|
|
|
|
sleep 45 # Delay for 45 seconds before fetching logs
|
|
|
|
run: sleep 45
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Fetch AWX Job Logs
|
|
|
|
|
|
|
|
run: |
|
|
|
|
|
|
|
|
# Fetch the most recent job from AWX
|
|
|
|
|
|
|
|
job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id')
|
|
|
|
job_id=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/job_templates/13/jobs/?order_by=-id | jq -r '.results[0].id')
|
|
|
|
|
|
|
|
|
|
|
|
# Fetch the logs for the job
|
|
|
|
|
|
|
|
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=json)
|
|
|
|
logs=$(curl -s -H "Authorization: Bearer ${{ secrets.AWX_API_TOKEN }}" https://awx.mafyuh.xyz/api/v2/jobs/$job_id/stdout/?format=json)
|
|
|
|
|
|
|
|
echo "AWX Job Logs for folder: $folder"
|
|
|
|
# Display the logs
|
|
|
|
|
|
|
|
echo "Range:"
|
|
|
|
echo "Range:"
|
|
|
|
echo "Start: $(echo "$logs" | jq -r '.range.start')"
|
|
|
|
echo "Start: $(echo "$logs" | jq -r '.range.start')"
|
|
|
|
echo "End: $(echo "$logs" | jq -r '.range.end')"
|
|
|
|
echo "End: $(echo "$logs" | jq -r '.range.end')"
|
|
|
|
echo "Absolute End: $(echo "$logs" | jq -r '.range.absolute_end')"
|
|
|
|
echo "Absolute End: $(echo "$logs" | jq -r '.range.absolute_end')"
|
|
|
|
echo "Content:"
|
|
|
|
echo "Content:"
|
|
|
|
echo "$(echo "$logs" | jq -r '.content')"
|
|
|
|
echo "$(echo "$logs" | jq -r '.content')"
|
|
|
|
|
|
|
|
done
|
|
|
|