Monday, February 8, 2016

Using Chef to automate Octopus Deployments

If you are using Octopus Deploy to deploy your .Net code to your Windows servers and also using AWS Auto Scaling Groups, you may have come across some of the limitations of Octopus. Primarily, Octopus has no built-in process to deploy the current project release to a newly registered tentacle immediately upon the tentacle registration. Tentacles can either be registered as 'polling' or 'listening' tentacles.  Polling tentacles will periodically check with the Octopus server to determine if a deployment is required, while a listening tentacle will wait until a deployment is pushed from the Octopus server.  Neither of these approaches will deploy the release immediately.  This post will provide a process of using a Chef recipe to configure the Octopus tentacle in listening mode and then initiate a deployment of the latest project release from the Octopus Server using an API call.

I must give credit to CodeKing and his article of how to use Octopus Deploy with AWS.  His script provides the steps necessary to query the Octopus server for the latest project release and to initiate the deployment. Here is his post:

The process I will demonstrate will rely on Chef to register the Octopus Tentacle as well as initiating the deployment of the latest project release to the server.  I'm not going to go into details about using Chef, if you need help using Chef please refer to their documentation at:

The recipe assumes the following:
  • Amazon's AWS CLI is installed on the server (this can be done using another chef recipe)
  • The server has access to S3 to download files to install Octopus Tentacle
  • The Octopus project is configured to increment version numbers
  • An Octopus account with an API key that has proper permissions to deploy the release.

The recipe will perform the following tasks:
  1. Download the Octopus Tentacle installer.
  2. Install Octopus Tentacle
  3. Register the Octopus Tentacle to the Octopus Server
  4. Deploy the latest project release from Octopus Server

1. Download the Octopus Tentacle installation from S3
It's not necessary to put the installer file on S3, but I prefer this approach as I know the file will always be available, vs relying on a web link that could potentially change.

Modify this script to use your S3 bucket

2. Install Octopus Tentacle
With the installer downloaded, we must now install Octopus on the server.

3. Register the Octopus Tentacle to the Octopus Server
The next step is to configure and register the Octopus tentacle to the Octopus server. This will register the tentacle using the server hostname, which is later used for the deployment process.

Modify this script to use your Octopus server, API key, and role

4. Deploy the latest release
The final step is to query the Octopus server for the latest release of the specified project and then make an API call to the Octopus server to initiate a deployment to the server.

Modify this script to use your Octopus server, Project, and API key,

Running Chef - putting it all together
The above steps can be placed into a single Chef recipe or kept into separate recipes and run individually.  I prefer to put these in a single recipe and call it via the Chef run-list.

I currently use Chef-Solo and therefore make a call like this, specifiying the runlist as well as the environment.
chef-solo -c c:/chef/solo.rb -j c:/chef/runlist.json -E development -L c:/chef/log.log -l info


Anonymous said...

Hi Ryan,
These steps have been really great. I have completed step 3 but I am confused on step 4.

1. Shouldn’t the polling tentacle automatically be polling for any new updates as soon as step 3 is completed?

2. In step 4 did you install a cookbook to get this file: c:/chef/cookbooks/octopus/files/octopus/Octo.exe
I don’t have that file in my cookbooks. I have checked the Octopus cookbook at but that file is not contained in there too.

3. If there are multiple projects assigned to a role how is that added to your script in step 4?

Thank you so much for your information to assist in setting up Octopus.

Ryan Lawyer said...

Alex, to answer your questions

1. Theoretically yes, but I found it faster to initiate it.

2. Good catch, I included the Octo.exe file within my custom cookbook. You can download the latest from Octopus site, choose the Command Line download

3. This was assuming for a single Project. I do have a process to utilize multiple projects, here is some info to help out.

Comma separate the Projects in the assigned role, ie: 'OctopusProjects' => "Project1,Project2"

In your PowerShell create an array and then cycle through each Project and deploy it.
Something like this:
foreach ($project in $projects){

Hope that helps