Automatically add FOG Snapin on registration
-
Hey All,
I was wondering if there is a way to automatically add a snapin to every computer that registers with the FOG server and needs to be joined to the domain? I know that is very specific, but there are cases where we have machines that don’t need to be joined to the domain and don’t need the snapin software.
Any help would be much appreicated!
Thanks,
-
You could simply create a group that has those specific snap-ins assigned to them and then modify the fog.man.reg or which ever file is being referenced for your registration process to take in a group id. Then pass that to your registration by changing the body of the full_reg function in the lib/reg-task/registration.class.php to update the host’s group. If your fog configuration doesn’t already make the tasks for pushing snap-ins then create some tasks using the host.class.php to queue up those in the same full_reg function at the end after you have created and saved the host.
-
Settings regarding hosts aren’t applied to groups, they are applied to hosts. So if you had a group of 100, applied a snapin using the group, and then added another host to the group - the new host would not have the snapin you applied previously.
@Chris-Whiteley what I’d suggest is creating a group for this specific snapin only. Name it to reflect this. When you register computers, you have the option of adding them to a group - add them there. Then later after registration, Use the group to apply the snapin. Once your done, remove those hosts from that group so they don’t get the snapin applied a second time later on (unless it doesn’t matter).
-
Thank you both for the replies! I would love to edit the fog.menu.reg to automatically select the snapin and not even ask the user about it. What would I do to make that happen? It is currently snapin ID = 3.
#!/bin/bash . /usr/share/fog/lib/funcs.sh clearScreen displayBanner disks="" disk="" hd="" getHardDisk sysman="" sysman64="" sysproduct="" sysproduct64="" sysversion="" sysversion64="" sysserial="" systype="" biosversion="" biosvendor="" biosdate="" mbman="" mbproductname="" mbversion="" mbserial="" mbasset="" cpuman="" cpuversion="" cpucurrent="" cpumax="" mem="" hdinfo="" caseman="" casever="" caseserial="" casesasset="" sysserial64="" systype64="" biosversion64="" biosvendor64="" biosdate64="" mbman64="" mbproductname64="" mbversion64="" mbserial64="" mbasset64="" cpuman64="" cpuversion64="" cpucurrent64="" cpumax64="" mem64="" hdinfo64="" caseman64="" casever64="" caseserial64="" casesasset64="" dots "Using disk device" echo $hd echo " * Starting host registration" mac=$(getMACAddresses | base64) exists=$(curl -ks --data "mac=$mac" http://${web}service/man.hostexists.php 2>/dev/null) checkAndSet() { local testvar="$1" local onlynum="$2" [[ -z $testvar ]] && return if [[ $onlynum =~ [Tt][Rr][Uu][Ee] && $testvar =~ ^[0-9]+$ ]]; then echo $testvar | base64 elif [[ $testvar =~ ^[0-9,]+$ ]]; then echo $testvar | base64 else return fi } setIDs() { local varVar="$1" local str="$2" local csvstyle="$3" local dummy="$4" local max="$5" local res="" local url="" local oIFS=$IFS local line="" while [[ -z ${!varVar} ]]; do [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Enter the $str IDs separated with , to associate with computer (? for listing): " || echo -n " Enter the $str ID to associate with computer (? for listing): " read dummy dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') case $dummy in [?]) url="http://${web}service/${str}listing.php" clearScreen res=$(echo -e $(curl -ks $url 2>/dev/null)) i=0 IFS=$'\n' for line in $res; do let i+=1 echo $line if [[ $i -eq $max ]]; then [[ $csvstyle =~ [Tt][Rr][Uu][Ee] ]] && echo -n " Press [Enter] to proceed or enter the $str IDs separated with , to associate with computer: " || echo -n " Press [Enter] to proceed or enter the $str ID to associate with computer: " read dummy case $dummy in [?]|"") i=0 clearScreen continue ;; esac case $csvstyle in [Tt][Rr][Uu][Ee]) [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" break ;; *) [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" break ;; esac i=0 dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') clearScreen fi done ;; ""|0) printf -v "$varVar" 0 ;; *) dummy=$(echo $dummy | sed -e 's/^,//' -e 's/,$//') [[ -z $dummy ]] && setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" case $csvstyle in [Tt][Rr][Uu][Ee]) [[ $dummy =~ ^[0-9,]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy) || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" ;; *) [[ $dummy =~ ^[0-9]+$ ]] && printf -v "$varVar" $(checkAndSet $dummy "true") || setIDs "$varVar" "$str" "$csvstyle" "$dummy" "$max" ;; esac ;; esac done IFS=$oIFS } [[ $exists != "#!ok" ]] && handleError "Unable to register host: $exists ($0)\n Args Passed: $*" host="" ip="" productKey="" imageid="" primaryuser="" other1="" other2="" blImage="" blDoAddGroup="" blDoAddSnapin="" keyEnter="" blDoAD="" res="" while [[ $res != "#!ok" ]]; do echo -n " * Enter hostname for this computer: " read host if [[ ${#host} -gt 15 ]]; then host=${host:0:15} echo " | Truncated to 15 characters: $host" usleep 2000000 fi host=$(echo $host | base64) res=$(curl -ks --data "host=$host" http://${web}service/hostnameloop.php 2>/dev/null) [[ $res != "#!ok" ]] && echo "$res" done imageid="" setIDs "imageid" "image" "" "" 20 if [[ $(curl -ks http://${web}service/locationcheck.php 2>/dev/null) == "##" ]]; then while [[ -z $askme ]]; do echo -n " Would you like to assign a location for this host? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) setIDs "locationid" "location" "" "" 20 location64=$locationid ;; *) askme="" echo " * Invalid input, please try again" ;; esac done fi askme="" while [[ -z $askme ]]; do echo -n " Would you like to associate this host with groups? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) setIDs "groupid" "group" "true" "" 20 group64=$groupid ;; *) askme="" echo " * Invalid input, please try again" ;; esac done askme="" while [[ -z $askme ]]; do echo -n " Would you like to associate this host with snapins? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) setIDs "snapinid" "snapin" "true" "" 20 snapin64=$snapinid ;; *) askme="" echo " * Invalid input, please try again" ;; esac done askme="" while [[ -z $askme ]]; do echo -n " Would you like to associate a product key to this host? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) echo -n " * Enter the product key for this computer: " read productKey productKey=$(echo $productKey | base64) ;; *) askme="" echo " * Invalid input, please try again" ;; esac done askme="" while [[ -z $askme ]]; do echo -n " Would you like this host to join a domain, (using default settings)? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) blDoAD=$(echo -n 1 | base64) askme="Y" ;; *) askme="" echo " * Invalid input, please try again" ;; esac done askme="" while [[ -z $askme ]]; do echo -n " Would you like to deploy image to this computer now? (y/N) " read askme case $askme in [Nn]|[Nn][Oo]|"") askme="N" ;; [Yy]|[Yy][Ee][Ss]) tmp="" ret="" retry=3 while [[ $ret != "#!ok" && ! $retry -eq 0 ]]; do echo " * Enter FOG GUI Username and Password" echo -n " Username: " read username echo -n " Password: " read -s password user64=$(echo $username | tr -d '\012' | base64) pass64=$(echo $password | tr -d '\012' | base64) ret=$(curl -ks --data "mac=$mac&username=$user64&password=$pass64" http://${web}service/checkcredentials.php 2>/dev/null) case $ret in '#!ok') echo echo " * This host will reboot and deployment will start!" ret=$tmp realdoimage=$(echo -n 1 | base64) break ;; '#!il') echo echo " * Error: Invalid Login! ($retry remaining)" let retry-=1 ;; esac done askme="Y" ;; *) askme="" echo " * Invalid input, please try again" ;; esac done dots "Attempting to register host" res="" while [[ -z $res ]]; do res=$(curl -ks --data "mac=$mac&advanced=$(echo -n 1 | base64)&host=$host&imageid=$imageid$realdoimage&doad=$blDoAD&location=$location64&username=$user64&groupid=$group64&snapinid=$snapin64&productKey=$productKey" http://${web}service/auto.register.php 2>/dev/null) echo "$res" usleep 2000000 done . /bin/fog.inventory usleep 2000000```
-
Based on the complexity requirements alone, this isn’t something easily done. Though depending on the version of FOG you’re using, you could create a crontab that could lookup all your hosts, see which are set to join the domain, and add any snapins you want automatically. You can even use the same principle during a deploy task through the use of postdownload scripts. Check if ad is to be used, if so, set the snapin for that host, and schedule that snapin task, then complete.
Of course i’m talking complex stuff to think about. But ultimately it’s not impossible, but it’s not automated in fog. Complexity level, i think, would be around a 6 or 7 on a 10 base scale meaning it’s not simple by any means, but it’s also not too hard. There’s some information on the use of the api system (assuming you’re using a version of fog with the api stuff) floating around the forums.