How can I mass register new Octopus Deploy tentacles?

tentacles
ask-octopus
api
(Ryan Rousseau) #1

We’re onboarding a new team onto Octopus. We’ve installed the Tentacle on the new machines. Can we automate the registration of the new tentacles so that we don’t have to register them manually?

(Ryan Rousseau) #3

You can automate the registration of these tentacles and there are two ways that you can do this.

Method 1

The first method is to use Tentacle.exe and the register-with command.

This will work if you can run the command against each target individually.

tentacle.exe register-with --server "https://your.octopus.url" --apiKey "API-YOURAPIKEY" --space "Default" --env "Development" --role "MyProject-Web"

Method 2

Another way to accomplish this is to use an API script to register each of the new targets with Octopus.

Here’s an example script that will discover and register tentacles given the host names or IP addresses and port numbers. You can customize it to pull the tentacleinformation from an external source or generate it programmatically.

$octopusBaseUrl = "https://your.octopus.url"
$apiKey = "API-YOURAPIKEY"
$spaceId = "Your Space Id"

$environmentIds = @("Environments-1", "Environments-2", "Environments-3")
$tentacleRoles = @("MyProject-Web")

$header = @{ "X-Octopus-ApiKey" = $apiKey }

$tentacles = @(
   @{
       Host  = "target1hostname"
       Port = "10933"
    },
   @{
        Host = "target2hostname"
        Port = "10933"
    }
)

foreach ($tentacle in $tentacles) {
    $discoverData = Invoke-RestMethod "$octopusBaseUrl/api/$spaceId/machines/discover?host=$($tentacle.Host)&port=$($tentacle.Port)&type=TentaclePassive" -Method Get -Headers $header

    $body = @{
        Name           = $discoverData.Name
        Endpoint       = $discoverData.Endpoint
        EnvironmentIDs = $environmentIds
        Roles          = $tentacleRoles
        IsDisabled     = $false
    } | ConvertTo-Json -Depth 10

    Invoke-RestMethod "$octopusBaseUrl/api/$spaceId/machines" -Headers $header -Method Post -Body $body
}