@danieln said in Using Snap Ins to run scripts post imaging...?:
@JJ-Fullmer Thanks for the reply! This is helpful.
I feel like maybe the best way to go about it is to assign the Snap In to each host. Just to confirm, this will deploy the Snap In after each time that host is image, regardless of which image it receives?
Yes that is correct, unless you specify otherwise (I think that’s really only available in the api though) the standard operation is to queue all assigned snapins to deploy after an image task
I’m also thinking of separating my inventory into FOG Groups by computer model and then assigning the Image Associated with it and Snap Ins at the group level.
Is this QC check also installing and or checking drivers? You could also use postdownload scripts to install drivers and have just 1 image that is universal and the drivers are injected and installed during sysprep specialize phase. Takes some setting up but works very well, see https://docs.fogproject.org/en/latest/kb/how-tos/post-download-scripts/?h=post
Also, if you wanted to create groups based on the model in the FOG Inventory you could build that out pretty quickly with my FogApi powershell module ( see my signature)
Something like this would get you a list of all unique model names you have in fog, this example uses is for 1.6 but should also work in 1.5.10.x
It also doesn’t include the initial api connection bits.
#get all your fog hosts with full details
$allhosts = Get-FogHosts | % { (Get-foghost -hostID $_.id -ea 0)}
#get the sysproduct field from the inventory of each host, and get the unique entries only
$uniqueModelNames = ($allhosts).inventory.sysproduct | sort-object -Unique
#list the model names in the shell
$uniqueModelNames
There may be some additional filtering to do here depending on your inventory (like HP sometimes has slight differentiations of a model) but if that list is what you want your groups to be
$uniqueModelNames | Foreach-object {
$jsonObj = @{
name = $_;
description = "Computers that are of the model $($_)"
}
#I have a pending issue for creating a simple New-FogGroup function
new-fogobject -type object -coreObject group -jsonData ($jsonObj | convertto-json)
}
Then you’d set the membership of the matching hosts
#loop through the model names you created groups of by name
$uniqueModelNames | Foreach-object {
#get the group name and the matching group object
$groupname = $_;
$group = get-FogGroupByName -name $groupName;
#find any host that is the given model and loop through them
$allhosts | Where-object { $_.inventory.sysproduct -eq $groupName;} | Foreach-Object {
#set the group association/membership required fields
$jsonGroupData = @{
groupID = $group.id
hostID = $_.id
}
#create the group membership association
New-FogObject -type object -coreObject groupassociation -jsonData ($jsonGroupData | convertto-json) -ea 0;
}
}
Then you can go in the Fog web gui and assign hosts to each image. This can also be done in the api, but I just don’t have time to work out an example for that.
Also note that groups are not persistent config containers. Group membership sticks around, but it’s meant to be used as a bulk setter. If you set an image in a host it will set it on all the hosts in the group. But if you go change the image on 1 host in the group, it doesn’t auto change back, nor does it auto set when you add it to a group. There is a plugin that changes this behavior called persistent groups, but using it as a bulk setting and as a simple container/organizer of hosts is usually sufficient as you get into things more and more.