Tentacle registration fails with System.IO.DirectoryNotFoundException

Hello,

In our team we are performing the next sequence when deploying two different web servers using Windows server AMIs in AWS.

  1. Start a base windows instance and apply some patches and updates (This step install a tentacle in the instance). We deregister the tentacle once done
  2. Create a base AMI base in the instance.
  3. For each of the web servers, we start a new instance based in the AMI created in the step 2 and perform the needed configuration steps. We deregister the tentacle at the end of the deployment.

With this configuration, we face the problem that both web serves have the same tentacle thumbprint in the step 3 because they are using the same base image that was created in the step 1 and generated a certificate at that point. Therefore, if we try to deregister one of the tentacles we deregister both of them.

The solution I tried to apply was to recreate the certificate and reset the trust relation with the octopus server. I used the powershell script below to install and configure the tentacle in the step 3

This is the powershell scrip I run

choco uninstall octopusdeploy.tentacle -y
choco install octopusdeploy.tentacle -y --version $tentacleVersion

$ipAddress = (Get-NetAdapter | ? status -eq ‘up’ | Get-NetIPAddress -ea 0 | ? addressfamily -eq ‘IPv4’).IPAddress
cd “${env:ProgramFiles}\Octopus Deploy\Tentacle”
& .\Tentacle.exe create-instance --instance “Tentacle” --config $tentacleConfigFile --console
& .\Tentacle.exe new-certificate --instance “Tentacle” --console
& .\Tentacle.exe configure --instance “Tentacle” --reset-trust --console
& .\Tentacle.exe configure --instance “Tentacle” --trust $octopusServerThumbprint --console
& .\Tentacle.exe configure --instance “Tentacle” --home $tentacleHomeDirectory --console
& .\Tentacle.exe configure --instance “Tentacle” --app $tentacleAppDirectory --console
& .\Tentacle.exe configure --instance “Tentacle” --port $tentacleListenPort --noListen “True” --console
& .\Tentacle.exe register-with --instance “Tentacle” --server $octopusServerUrl --environment $environment --role $role --name $env:COMPUTERNAME --publicHostName $ipAddress --apiKey $apiKey --comms-style TentacleActive --force --console
& .\Tentacle.exe service --instance “Tentacle” --install --start --console

However, when trying to execute it during the booting of the instance in the userdatascript the registration command (register-with command) fails. This is what I found in the logs :

Octopus Deploy: Tentacle version 3.3.26 (3.3.26+Branch.master.Sha.dd437fbefe48f50b2571b13bd99daa4e34fc93cd)

Error: Could not find a part of the path ‘C:\Windows\system32\config\systemprofile\AppData\Local\Temp\Octo-45fe21a0-a24c-4db6-a139-ac3933a1c555’.

Full error details are available in the log files.
At: C:\Windows\system32\config\systemprofile\AppData\Local\Octopus\Logs

Could not find a part of the path ‘C:\Windows\system32\config\systemprofile\AppData\Local\Temp\Octo-45fe21a0-a24c-4db6-a139-ac3933a1c555’.
System.IO.DirectoryNotFoundException: Could not find a part of the path ‘C:\Windows\system32\config\systemprofile\AppData\Local\Temp\Octo-45fe21a0-a24c-4db6-a139-ac3933a1c555’.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at Octopus.Shared.Security.Certificates.CertificateEncoder.DoFromBase64String(String thumbprint, String certificateString, X509Store store) in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Security\Certificates\CertificateEncoder.cs:line 108
at Octopus.Shared.Configuration.TentacleConfiguration.get_TentacleCertificate() in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Configuration\TentacleConfiguration.cs:line 97
at Octopus.Tentacle.Commands.RegisterMachineCommand.Start() in Y:\Work\refs\tags\3.3.26\source\Octopus.Tentacle\Commands\RegisterMachineCommand.cs:line 65
at Octopus.Shared.Startup.AbstractCommand.Octopus.Shared.Startup.ICommand.Start(String[] commandLineArguments, ICommandRuntime commandRuntime, OptionSet commonOptions) in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Startup\AbstractCommand.cs:line 58
at Octopus.Shared.Startup.OctopusProgram.Start(ICommandRuntime commandRuntime) in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Startup\OctopusProgram.cs:line 221
at Octopus.Shared.Startup.ConsoleHost.Run(Action`1 start, Action shutdown) in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Startup\ConsoleHost.cs:line 72
at Octopus.Shared.Startup.OctopusProgram.Run() in Y:\Work\refs\tags\3.3.26\source\Octopus.Shared\Startup\OctopusProgram.cs:line 94

One interesting fact is that if I connect to the instance and try to run the command manually from powershell it works and the tentacle is registered in the server.

Could you please advise me with this issue? Thank you very much in advance.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.