Octopus Tentacle Automated Deployment And Registration

In post I’m going to cover Octopus Tentacle automated deployment and registration.

Recently I had situation where I had to install and then register Octopus Tentacles in Azure using ARM templates. The Octopus server was only reachable via public internet using it’s DNS name, by default Octopus will register using the local hostname which wouldn’t work in this case. I couldn’t find a complete example that did exactly what I needed, I’m posting the solution I came up with in case it is needed again.

There is some guidance here around ARM it but it doesn’t cover ARM templates only PowerShell scripts. I took this example anyway and modified it to be a DSC extension in my ARM template and it kind of worked. You can only use one instance of the DSC extension in a template since ARM will try to install it multiple times if you have multiple instances. I needed multiple instances and it failed. I uploaded the ARM example to GitHub anyway if someone needs it for Octopus servers installed in Azure.

In the end I used Azure Custom Script extensions to execute a PowerShell script for the installation. To create the PowerShell script I tried to follow the examples here using Tentacle.exe but still had the problem with the wrong tentacle URL. Using the Octopus.Client dll which was also part of the example didn’t work either, it didn’t configure the Windows service and it assumed you knew the tentacle client thumbprint which you don’t since this is a new installation and the tentacle will generate new thumbprint. Eventually I got it working using a combination of the two and some extra code to retrieve the tentacle client thumbprint. The full sample is here but I will highlight the important parts.

To retrieve the tentacle client thumbprint run:

$raw = .\Tentacle.exe show-thumbprint --nologo --console
	$client_thumbprint = $raw -Replace 'The thumbprint of this Tentacle is: ', ''

It will print the thumbprint to screen with some extra text you don’t need so I remove the first part.

Secondly don’t call the register-with command shown in the Tentacle.exe example since it will be done using the Octopus.Client dll.

To add multiple roles you have to add them one at a time, to achieve this I pass the roles string to PowerShell as a comma separated value.

"Web Server, Database Server"

And then I split it into an array and loop through it:

foreach($role in (New-Object -TypeName System.String -ArgumentList $roles).Split(','))
	{
		$tentacle.Roles.Add($role)
	}

After it is all done you will end up with a new machine in the desired environment with the correct URL.

Octopus Tentacle Automated Deployment And Registration

Francois Delport

Practical Tips And Tooling For Azure Resource Manager

Moving to Azure Resource Manager (ARM) can look daunting, especially when you are staring at a 1000+ line JSON ARM template that just failed deployment but once you get into it you will see it is not so bad. In this post I’m going to share some practical tips and tooling for Azure Resource Manager.

To read more about ARM and why you should use it instead of the classic Azure API take a look at this article for the official version. In my environment the main drivers for moving to ARM was RBAC and ARM deployment templates that make deployments to complex environments easier. Moving to ARM should not be an automatic decision just because it is new, you should evaluate the benefits first. At the time of writing this post there were no plans to discontinue the classic deployment model yet, so you still have time. That said for new projects I would suggest you use ARM and for existing ones look if you gain anything first before you migrate since it is not a trivial tasks for a large environment and a large script library.

Exploring The ARM API
If you use Azure PowerShell v1.0 or greater you will find the ARM cmdlets use the {verb}-AzureRM* naming convention to differentiate from the classic cmdlets, you can use Get-Help {cmdletname} -detailed to explore what each one does. If you use the Rest API directly you can use the ARM Explorer website to explore the Rest API against your own subscriptions. It is also useful to perform adhoc tasks if scripting is not necessary. ARM uses providers to manage the resources you can deploy, when you open ARM Explorer you can browse the list of providers registered with your subscription for example there are providers for computing, networking, websites etc.

Authoring ARM Templates
ARM templates make it easier to deploy complex environments using a declarative model to describe the resources that should be in the environment. The ARM deployment engine is clever enough to deploy the resources that are not there and to ignore the ones that exist already, it is like DSC for Azure. The templates are JSON and as we know, it is not the easiest thing to edit a large JSON document. Luckily you can use Visual Studio to make life easier, install the Azure SDK and add a new Azure Resource Group project to your solution. When you edit the JSON deployment templates and parameter files, there are schemas to validate the document, intellisense popups and the editor has some smarts around resources.

Practical Tips And Tooling For Azure Resource Manager

There is a large library of quick start templates on gitbub at this link. You can also export a template representing the resources currently in a resource group by opening the resource group in the portal and selecting export under the settings section, official block post here. This can also be accomplished from PowerShell using the Save-AzureRmResourceGroupDeploymentTemplate cmdlet.

Side Note: You can also use the ARMViz webapp to visualise and edit ARM templates.

Deploying ARM Templates
Deploying  your template is also easy, you right click on the project in Visual Studio and choose deploy. It will show a popup to choose the subscription, resource group, template and parameter files etc.

If you used the Visual Studio ARM project you will see it contains a PowerShell script called Deploy-AzureResourceGroup.ps1 that will run the ARM deployment.   The PowerShell command called New-AzureRmResourceGroupDeployment will run the deployment. If you want to validate your template you can use the Test-AzureRmResourceGroupDeployment command.

TroubleShooting Tips:

  • You can set the log level of the deployment and retrieve the detailed logs afterwards more here.
  • The Templates blade in the new portal can run ARM Templates and it performs more validation before executing and gives more descriptive error messages when failures occur than PowerShell or VisualStudio deployments.
  • You can view the audit logs and errors for your deployments in the Audit Logs blade in the new portal.

Francois Delport