Create New Host with API - Snapins wont install - Rename Host not working.
-
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=8SNAPIN_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/nullecho “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.”
fiecho -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.”
fiCheers
Chris -
This are The Option I want to set with API after creating the Host in FOG:
After Imaging, Snapins wont be installed automaticaly. Is there a Task missing?
For some Reason i get this Message in the fog.log on the client.20.05.2025 11:10:48 Middleware::Response No snapins
20.05.2025 11:10:48 Middleware::Communication URL: http://10.0.96.10/fog/management/index.php?sub=requestClientInfo&configure&newService&json 20.05.2025 11:10:48 Middleware::Response Success 20.05.2025 11:10:48 Middleware::Communication URL: http://10.0.96.10/fog/management/index.php?sub=requestClientInfo&mac=00:2B:67:99:C6:BC|58:EF:68:E6:5D:73|F8:AC:65:E2:94:65|F8:AC:65:E2:94:66|FA:AC:65:E2:94:65|F8:AC:65:E2:94:69&newService&json 20.05.2025 11:10:48 Middleware::Response Success 20.05.2025 11:10:48 Middleware::Communication URL: http://10.0.96.10/fog/service/getversion.php?clientver&newService&json 20.05.2025 11:10:48 Middleware::Communication URL: http://10.0.96.10/fog/service/getversion.php?newService&json 20.05.2025 11:10:48 Service Creating user agent cache 20.05.2025 11:10:48 Middleware::Response Invalid time 20.05.2025 11:10:48 Middleware::Response No Printers 20.05.2025 11:10:48 Middleware::Response Module is disabled globally on the FOG server ------------------------------------------------------------------------------ ---------------------------------ClientUpdater-------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response Success ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ ----------------------------------TaskReboot---------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response Success ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ --------------------------------HostnameChanger------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response Success 20.05.2025 11:10:48 HostnameChanger Users still logged in and enforce is disabled, delaying any further actions ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ ---------------------------------SnapinClient--------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response No snapins ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ --------------------------------PrinterManager-------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response No Printers ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ --------------------------------PowerManagement------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response Success 20.05.2025 11:10:48 PowerManagement Calculating tasks to unschedule 20.05.2025 11:10:48 PowerManagement Calculating tasks to schedule ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ ----------------------------------UserTracker--------------------------------- ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Client-Info Client Version: 0.13.0 20.05.2025 11:10:48 Client-Info Client OS: Windows 20.05.2025 11:10:48 Client-Info Server Version: 1.5.10.1655 20.05.2025 11:10:48 Middleware::Response Success ------------------------------------------------------------------------------ 20.05.2025 11:10:48 Service Sleeping for 133 seconds
Greez
Chris