How can I convert my polling tentacles to listening tentacles

We originally created all our tentacles as polling tentacles. Our network team has updated its policies and now we can leverage listening tentacles. How can we easily convert all our polling tentacles to listening tentacles?

This functionality is included in the CloneTentacleInstance.ps1 script in the SpaceCloner project.

The easiest way to do this is to use a runbook. In a nutshell, the runbook will:

  • Use the polling tentacle to create the listening tentacle instance
  • Register the listening tentacle with Octopus Deploy
  • Disable the polling tentacle and rename it as “_old”
  • Run a health check to add the new listening tentacle to the run and remove the polling tentacle
  • Use the listening tentacle to deregister the polling tentacle and delete the instance

Prep Work

The SpaceCloner leverages GitHub releases. This means we can use like a regular package in a runbook run. To do that we first need to make sure GitHub has been added as an external feed:

After the GitHub feed has been added we will want to create a new project and add these variables to it:

Please Note replace the Thumbprint, URL, and API key with values from your server.

Runbook

The runbook process is:

Step 1

The script for step 1 is

$sourceInstanceName = $OctopusParameters["Project.Source.Tentacle.Instance.Name"]
$destinationInstanceName = $OctopusParameters["Project.Destination.Tentacle.Instance.Name"]
$portNumber = 10933
$destinationThumbprint = $OctopusParameters["Project.Octopus.Thumbprint"]
$apiKey = $OctopusParameters["Project.Octopus.ApiKey"]
$url = $OctopusParameters["Project.Octopus.Url"]
$extractedPath = $OctopusParameters["Octopus.Action.Package[SpaceCloner].ExtractedPath"]
$spaceName = $OctopusParameters["Octopus.Space.Name"]
$machineHostName = $OctopusParameters["Octopus.Machine.Name"]
$whatIf = $true

Set-Location $extractedPath

.\CloneTentacleInstance.ps1 -SourceOctopusUrl $url -SourceOctopusApiKey $apiKey -sourceSpaceName $spaceName -DestinationOctopusUrl $url -DestinationOctopusApiKey $apiKey -DestinationSpaceName $spaceName -DestinationOctopusServerThumbprint $destinationThumbprint -TentacleInstanceNameToCopy $sourceInstanceName -ClonedTentacleType "Listening" -ClonedListeningPort $portNumber -ClonedInstanceName $destinationInstanceName -WhatIf $whatif -ClonedTentacleHostName $machineHostName

Please Note This is assuming the machine name registration == your host name. If it does not you’ll need to update the script to account for that.

It references the SpaceCloner package and runs on deployment targets for a specific role:

The package reference is:

Step 2

This step is a manual intervention step, add it, along with any instructions you think are important.

When reviewing the script you will want to look at the register with command as well as the renamed text.

image

Step 3

The script for step 3 is the same as step 1 except the what if value is set to $false

$sourceInstanceName = $OctopusParameters["Project.Source.Tentacle.Instance.Name"]
$destinationInstanceName = $OctopusParameters["Project.Destination.Tentacle.Instance.Name"]
$portNumber = 10933
$destinationThumbprint = $OctopusParameters["Project.Octopus.Thumbprint"]
$apiKey = $OctopusParameters["Project.Octopus.ApiKey"]
$url = $OctopusParameters["Project.Octopus.Url"]
$extractedPath = $OctopusParameters["Octopus.Action.Package[SpaceCloner].ExtractedPath"]
$spaceName = $OctopusParameters["Octopus.Space.Name"]
$machineHostName = $OctopusParameters["Octopus.Machine.Name"]
$whatIf = $false

Set-Location $extractedPath

.\CloneTentacleInstance.ps1 -SourceOctopusUrl $url -SourceOctopusApiKey $apiKey -sourceSpaceName $spaceName -DestinationOctopusUrl $url -DestinationOctopusApiKey $apiKey -DestinationSpaceName $spaceName -DestinationOctopusServerThumbprint $destinationThumbprint -TentacleInstanceNameToCopy $sourceInstanceName -ClonedTentacleType "Listening" -ClonedListeningPort $portNumber -ClonedInstanceName $destinationInstanceName -WhatIf $whatif -ClonedTentacleHostName $machineHostName

Step 4

The second step is the machine health check. It will remove the old polling tentacle from this run and add the new tentacle.

Step 5

The final step uses the listening tentacle to remove the polling tentacle from the instance.

$sourceInstanceName = $OctopusParameters["Project.Source.Tentacle.Instance.Name"]
$octopusServer = $OctopusParameters["Project.Octopus.Url"]
$apiKey = $OctopusParameters["Project.Octopus.ApiKey"]
$spaceName = $OctopusParameters["Octopus.Space.Name"]

if ($null -eq $TentacleInstallDirectory)
{
    if ($IsLinux)
    {
        $TentacleInstallDirectory = "/opt/octopus/tentacle"
    }
    else
    {
        $TentacleInstallDirectory = "C:\Program Files\Octopus Deploy\Tentacle"    
    }    
}
$tentacleExe = [System.IO.Path]::Combine($TentacleInstallDirectory, "Tentacle")

& $tentacleExe deregister-from --instance $sourceInstanceName --server $octopusServer --apiKey $apiKey --space $spaceName --multiple
& $tentacleExe delete-instance --instance $sourceInstanceName

Wrap Up

Assuming everything goes as planned you will should see messages similar to this: