Powershell Script multiple roles per host

Hello all

Does anyone know who you would add multiple roles within my powershell script, for deplying tentacles ??
As this doesnt work

$odtroles = “web,api,service”

Tentacle.exe register-with --instance “Tentacle” --server $odtserver --apiKey=$odtapi --role $odtroles --environment $odtenv --comms-style TentaclePassive --console --force

Would it be:
$odtroles = “web”,“api”,“service”

or something else ?

Regards

James

Hi James,

Thanks for reaching out. It should be --role "Role1" --Role "Role2" and so on.

Best regards,
Dalmiro

Hello Dalmiro

When I add more than two arguments for --role, it doesn’t recognize the next argument in string, so for example below, it will complain about doesn’t recognize --environment

Example:

Tentacle.exe register-with --instance “Tentacle” --server $odtserver --apiKey=$odtapi --role $odtrole --role $odta --role $odtb --environment $odtenv --comms-style TentaclePassive --console --force

Is there a better approach to this ?

As we could have for our DEV / UAT environments a single node with 5 to 8 roles assigned to them ?

Or can we dynamically populate these variables based on hostname ?

Regards

James

Hi James,

Sorry for the delay here. I’ve tested this in my lab and it seems to work just fine (See attached screenshots).

Which version of the Tentacle are you using? It says it on the console every time you execute a Tentacle.exe command. I’ve used 3.3.11 to test this.

Regards,
Dalmiro

Forgot to attach the screenshots :slight_smile:

2.RegisteredMachine.jpg

ADMIN

Please remove my attachments from my last post please.

@Gsandoval - I removed the whole comment and opened a separate PRIVATE conversation for it: http://help.octopusdeploy.com/discussions/questions/9449

I was able to get this working, my script does the following below.

  • Install the tentacle
  • Change the host name to to the Instance ID from it’s metadata
  • Register (1) Environment
  • W/ 3 Roles

Note: This script is JSON below as it’s in my Cloud Formation Template in AWS, you can convert it back to a .ps1 if you’ll need to use it as a Power Shell script.

“C:\cfn\octopustentacle.ps1”: {
“content”: {
“Fn::Join”: [
"", [
“Start-Transcript -path “E:\Octopus\TentacleInstallLog.txt””, “\n”,
"$tentacleDownloadPath = “https://download.octopusdeploy.com/octopus/Octopus.Tentacle.3.3.3-x64.msi”", “\n”,
"$octopusServerThumbprint = “YOUR_OWN_OCTOPUS_THUMBPRINT”", “\n”,
"$tentacleListenPort = 10933\n",
"$tentacleHomeDirectory = “E:\Octopus”", “\n”,
"$tentacleAppDirectory = “E:\Octopus\Applications”", “\n”,
"$tentacleConfigFile = “E:\Octopus\Tentacle\Tentacle.config”", “\n”,

                  "function Download-File\n",
                  "{\n",
                  "param ( \n",
                  "[string] $url,\n",
                  "[string] $saveAs \n",
                  ")\n",

                  "Write-Host \"Downloading\" $url to $saveAs\n",
                  "[System.Net.ServicePointManager]::Expect100Continue = $true;\n",
                  "[System.Net.ServicePointManager]::SecurityProtocol = `\n",
                  "[System.Net.SecurityProtocolType]::Ssl3 -bor `\n",
                  "[System.Net.SecurityProtocolType]::Tls -bor `\n",
                  "[System.Net.SecurityProtocolType]::Tls11 -bor `\n",
                  "[System.Net.SecurityProtocolType]::Tls12\n",


                  "$downloader = new-object System.Net.WebClient\n",
                  "$downloader.DownloadFile($url, $saveAs)\n",
                  "}\n",

                  "function Get-MyPublicIPAddress \n",
                  "{\n",
                  "Write-Host \"Getting public IP address\"\n",
                  "$ip = Invoke-RestMethod http://169.254.169.254/latest/meta-data/local-ipv4/ \n",
                  "return $ip \n",
                  "}\n",


                  "function Install-Tentacle \n",
                  "{\n",
                  "param (\n",
                  "[Parameter(Mandatory =$True)]\n",
                  "[string]$apiKey,\n",
                  "[Parameter(Mandatory =$True)]\n",
                  "[System.Uri]$octopusServerUrl,\n",
                  "[Parameter(Mandatory =$True)]\n",
                  "[string]$environment,\n",
                  "[Parameter(Mandatory =$True)]\n",
                  "[string]$role\n",
                  ")\n",

                  "Write-Output \"Beginning Tentacle installation\"\n",

                  "Write-Output \"Downloading latest Octopus Tentacle MSI...\"\n",

                  "$tentaclePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(\"\\Tentacle.msi\")\n",
                  "if ((test-path $tentaclePath) -ne $true) {\n",
                  "Download-File $tentacleDownloadPath $tentaclePath", "\n",
                  "} \n",

                  "Write-Output \"Installing MSI\"\n",
                  "$msiExitCode = (Start-Process -FilePath \"msiexec.exe\" -ArgumentList \"/i C:\\Tentacle.msi /quiet\" -Wait -Passthru).ExitCode\n",

                  "Write-Output \"Tentacle MSI installer returned exit code $msiExitCode\"\n",
                  "if ($msiExitCode -ne 0) {\n",
                  "throw \"Installation aborted\"\n",
                  "} \n",

                  "Write-Output \"Open port \"Inbound TCP/10933\" on Windows Firewall\"\n",
                  "& netsh.exe advfirewall firewall add rule name=\"Inbound TCP/10933\" dir=in action=allow protocol=TCP localport=10933", "\n",

                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed when modifying firewall rules\" \n",
                  "} \n",

                  "$ipAddress = Get-MyPublicIPAddress\n",
                  "$ipAddress = $ipAddress.Trim()", "\n",

                  "Write-Output \"Public IP address: \" + $ipAddress\n",


                  "Write-Output \"Configuring and registering Tentacle\"\n",
                  "cd \"${env:ProgramW6432}\\Octopus Deploy\\Tentacle\"\n",


                  "& .\\tentacle.exe create-instance --instance \"Tentacle\" --config $tentacleConfigFile --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on create-instance\"\n",
                  "} \n",

                  "& .\\tentacle.exe configure --instance \"Tentacle\" --home $tentacleHomeDirectory --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on configure\"\n",
                  "} \n",

                  "& .\\tentacle.exe configure --instance \"Tentacle\" --app $tentacleAppDirectory --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on configure\"\n",
                  "} \n",


                  "& .\\tentacle.exe configure --instance \"Tentacle\" --port $tentacleListenPort --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on configure\"\n",
                  "} \n",



                  "& .\\tentacle.exe new-certificate --instance \"Tentacle\" --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on creating new certificate\"\n",
                  "} \n",



                  "& .\\tentacle.exe configure --instance \"Tentacle\" --trust $octopusServerThumbprint --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on configure\"\n",
                  "} \n",



                 "& .\\tentacle.exe register-with --instance \"Tentacle\" --server \"http://OCTOPUS_SERVER_URL\" --apiKey \"YOUR_OWN_OCTOPUS_API_KEY\" --comms-style TentaclePassive --force --role \"ROLE1\" --environment \"YOUR_ENVIRONMENT\" --role \"ROLE2\" --role \"ROLE3\" --name $env:COMPUTERNAME --publicHostName $ipAddress --force --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on register-with\"\n",
                  "} \n",



                  "& .\\tentacle.exe service --instance \"Tentacle\" --install --start --console | Write-Host\n",
                  "if ($lastExitCode -ne 0) {\n",
                  "throw \"Installation failed on service install\"\n",
                  "} \n",



                  "Write-Output \"Tentacle commands complete\"\n",
                  "} \n",
                  "Install-Tentacle -apiKey \"YOUR_OWN_OCTOPUS_API_KEY\" -octopusServerUrl \"http://OCTOPUS_SERVER_URL\" -environment \"YOUR_ENVIRONMENT\" -role \"ROLE1\"\n"

Glad to hear you got it working!

Cheers