Hey! We were experimenting with the idea of “tagging” tentacles with metadata during a process step. We would essentially read the existing roles:
$machine = Invoke-RestMethod -Method Get `
-Uri "$octopusUrl/api/machines/$machineId" `
-Headers @{ "X-Octopus-ApiKey"=$octopusApiKey } `
-TimeoutSec 120
then keep the ones that defined the server type (“Application-Server”) and replace the ones that defined Octopus Project releases (“Code Release: 1.0.0”) the server. There would be several of these in our case since our Tentacles are affected by several projects.
# grabbed all of the tags we want to change from a file...
$roles = @()
$roles += ("Code: {0}" -f $OctopusParameters["Octopus.Release.Number"])
# extract current tentacle types
$machineTypes = $machine.Roles | % { if($_ -notmatch ":") { $_ } }
# add to roles
$roles += $machineTypes
# construct body
$body = ("{{
'Name' : '{0}',
'Thumbprint' : '{1}',
'Uri' : '{2}',
'EnvironmentIds' : ['{3}'],
'Roles' : ['{4}']
}}" `
-f $machine.Name,
$machine.Thumbprint,
$machine.Uri,
[System.String]::Join("','",$machine.EnvironmentIds),
[System.String]::Join("','",$roles))
Invoke-RestMethod -Method Put `
-Uri ("$octopusUrl/api/machines/{0}" -f $machine.Id) `
-Headers @{ "X-Octopus-ApiKey"=$octopusApiKey } `
-Body $body
-TimeoutSec 120
This seems to be working in that the tentacles now have the new roles, but most of them can’t signal that the step is complete to the server during the deployment. Is this because we’re messing with tentacle roles during an active deployment? Is there a better way to do this? This may seem overkill, but if we get a new machine due to an AutoScaling event and it requests its own code, we’d like to know at a glance from the Environments tab that all the machines are up to date.
Thanks!