Hello Together 🙂
today im trying to build a Script, which creates the Host in FOG.
Unfortunatily i cant manage, to get the Snapins installed to the host, after the Windows 11 Deployment is finished.
I already tried to create a second task with install only install snapins.
This is not Possible because the other deployment tast is still active after creating with script.
I just wan to write a script which is creating the host in FOG.
Then i want to connect to notebook to the Network and wait for the installation to be finished.
Would be awesome if someone can help me with a hint.
This is the Script i am Using:
#!/bin/bash
FOG_SERVER_ADDRESS=“http://10.0.96.10/fog”
GLOBAL_API_TOKEN=“token1”
USER_API_TOKEN=“token12”
HOSTNAME_NEU=“Test123”
MAC_ADRESSE_NEU=“10:20:30:40:50”
IMAGE_ID_NEU=8
SNAPIN_IDS_ZUZUWEISEN=(1 2 3 4 5 6)
DEPLOY_TASK_TYPE_ID=1
SHUTDOWN_AFTER_TASK=“false”
echo “Schritt 1: Erstelle Host mit aktivierten Modulen…” ( Create Host with modules enabled )
MODULE_IDS=“[1,2,3,4,5,6,7,8,9,10,11,12,13]”
JSON_PAYLOAD_CREATE=‘{
“name”: "’“${HOSTNAME_NEU}”‘“,
“macs”: [”’“${MAC_ADRESSE_NEU}”‘“],
“imageID”: ‘${IMAGE_ID_NEU}’,
“modules”: '”${MODULE_IDS}"’
}’
CREATED_HOST_RESPONSE=$(curl -s -X POST
-H “Content-Type: application/json”
-H “fog-api-token: ${GLOBAL_API_TOKEN}”
-H “fog-user-token: ${USER_API_TOKEN}”
-d “${JSON_PAYLOAD_CREATE}”
“${FOG_SERVER_ADDRESS}/host”)
HOST_ID=$(echo “${CREATED_HOST_RESPONSE}” | jq -r ‘.id’)
if [ -z “$HOST_ID” ] || [ “$HOST_ID” == “null” ]; then
echo “Fehler beim Erstellen des Hosts. Antwort: ${CREATED_HOST_RESPONSE}”
exit 1
else
echo “Host erfolgreich erstellt mit ID: ${HOST_ID}”
fi
######################## This option is not renaming computer#####################
echo -e “\nSchritt 1b: Setze chgHostname + forceReboot…”
JSON_AD_REBOOT=‘{
“chgHostname”: 1,
“forceReboot”: 1
}’
######################## This option is not renaming computer#####################
curl -s -X PUT
-H “Content-Type: application/json”
-H “fog-api-token: ${GLOBAL_API_TOKEN}”
-H “fog-user-token: ${USER_API_TOKEN}”
-d “${JSON_AD_REBOOT}”
“${FOG_SERVER_ADDRESS}/host/${HOST_ID}” > /dev/null
echo “Hostname-Änderung und erzwungener Reboot wurden aktiviert.”
echo -e “\nSchritt 2: Weise Snapins zu Host ${HOST_ID} zu…”
SNAPIN_JSON_ARRAY=“[”
FIRST_SNAPIN=true
for SNAPIN_ID in “${SNAPIN_IDS_ZUZUWEISEN[@]}”; do
if [ “$FIRST_SNAPIN” = false ]; then SNAPIN_JSON_ARRAY=“${SNAPIN_JSON_ARRAY},”; fi
SNAPIN_JSON_ARRAY=“${SNAPIN_JSON_ARRAY}${SNAPIN_ID}”
FIRST_SNAPIN=false
done
SNAPIN_JSON_ARRAY=“${SNAPIN_JSON_ARRAY}]”
JSON_PAYLOAD_UPDATE_SNAPINS=‘{
“snapins”: ‘${SNAPIN_JSON_ARRAY}’
}’
UPDATE_SNAPIN_RESPONSE=$(curl -s -w “\nHTTP_STATUS_SNAPIN:%{http_code}\n” -X PUT
-H “Content-Type: application/json”
-H “fog-api-token: ${GLOBAL_API_TOKEN}”
-H “fog-user-token: ${USER_API_TOKEN}”
-d “${JSON_PAYLOAD_UPDATE_SNAPINS}”
“${FOG_SERVER_ADDRESS}/host/${HOST_ID}”)
echo “Snapin Update Antwort: ${UPDATE_SNAPIN_RESPONSE}”
if [[ $(echo “${UPDATE_SNAPIN_RESPONSE}” | grep “HTTP_STATUS_SNAPIN:2”) ]]; then
echo “Snapins erfolgreich zugewiesen oder Anfrage verarbeitet.”
else
echo “Fehler oder unerwartete Antwort beim Zuweisen der Snapins.”
fi
echo -e “\nSchritt 3: Starte Image Deployment auf Host ${HOST_ID}…”
JSON_PAYLOAD_DEPLOY_TASK=‘{
“taskTypeID”: ‘“${DEPLOY_TASK_TYPE_ID}”’,
“shutdown”: ‘“${SHUTDOWN_AFTER_TASK,}”’,
“pending”: false
}’
DEPLOY_TASK_RESPONSE=$(curl -s -w “\nHTTP_STATUS_DEPLOY:%{http_code}\n” -X POST
-H “Content-Type: application/json”
-H “fog-api-token: ${GLOBAL_API_TOKEN}”
-H “fog-user-token: ${USER_API_TOKEN}”
-d “${JSON_PAYLOAD_DEPLOY_TASK}”
“${FOG_SERVER_ADDRESS}/host/${HOST_ID}/task”)
echo “Deploy Task Antwort: ${DEPLOY_TASK_RESPONSE}”
if [[ $(echo “${DEPLOY_TASK_RESPONSE}” | grep “HTTP_STATUS_DEPLOY:2”) ]]; then
echo “Image-Deploy-Task erfolgreich gestartet.”
else
echo “Fehler beim Starten des Deploy-Tasks.”
fi
Cheers
Chris