Updating Tentacle Roles during a deploy

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,

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.


Hi Jonathan,

Thanks for getting in touch. This looks like some serious Octopus wrangling you’re doing here! I’ve read through your post a few times and can see what you are doing, but I wonder: what is the core reason you want to use Roles this way?

My guess is that you want to have some way to look at a Machine and tell which Releases are deployed onto it (according to Octopus). Is that right, or can you steer me in the right direction?

If I’m correct, we are currently working on Octopus 3.4 which will include a bunch of new features to make working with elastic environments easier. Take a look at the early RFC (which is now a bit out of date, but still informative) and our EAP. As part of Octopus 3.4 we are looking at recording which releases are currently deployed onto a machine to make the “machine comes online and gets all of the latest releases deployed automatically” feature.

Regarding the behaviour you’re experiencing, we evaluate Machines at the beginning of a deployment, and that’s when Roles factor in to the equation. At least at a high level. In the end I’m not sure why you’re seeing this behaviour. To investigate it any further I would need you to send through the raw logs from your deployment.

Hope that helps!

Wow, you guys have been busy! It looks like a lot is being addressed that we’ve had to do manually (dead tentacles, self-requesting the first download, etc.) Is there a more private channel for me to send you the raw logs?

Hi Jonathan,

Thanks for getting back to me. You could make this discussion private, or open a new thread, make it private, and post your logs to me.

Hope that helps!