Search code examples
chef-infrachef-recipecookbookoctopus-deployberkshelf

How do I override octopus-deploy's supermarket chef cookbook's tentacle_install_location path?


My current setup:

I am creating a cookbook to install Octopus Deploy tentacles onto standard VMs at my company. I have created a new local cookbook called "octopus-deploy-mk6". "mk6" is our company's name and I'm using this recipe to define my company specific installation requirements. I have added a Berksshelf dependency to the supermarket community cookbook named "octopus-deploy". Here is a link to "octopus-deploy":

Octopus-deploy supermarket link

I included the supermarket cookbook via a berksshelf depend statement in the chef-repo/metadata.rb file:

depends 'octopus-deploy', '~> 0.4.3'

And I put it in the following in a recipe in the chef-repo/cookbooks/octopus-deploy-mk6/recipes/default.rb file (note, I've found that the checksum in the examples wasn't needed):


    octopus_deploy_tentacle 'Tentacle' do
      action :install
      version '3.1.5'
    end

When I do the "berks install", "berks update" and "knife cookbook upload octopus-deploy-mk6" commands, it installs the Octopus Deploy Tentacle very nicely. The recipe actually exceeds my expectations. Thank you to Brent Montague (if you happen to read this) for creating the cookbook.

Please feel free to let me know if I'm not doing this setup correct, I'm very new to Chef.

Here's the question:

Our corporate standard for installing Octopus Deploy tentacles is to install it in: "C:\Program Files (x86)\Octopus\Tentacle" and the supermarket cookbook installs it in "C:\Program Files\Octopus Deploy\Tentacle". While I personally like the directory name picked by the supermarket cookbook better, the corporate standard is to put it into the x86 directory and Octopus sub-directory and I can't change the standard. How do I override the default tentacle installation location?

The easy solution to this issue would be to use "copy and paste reuse" and simply copy the whole community cookbook into my octopus-deploy-mk6 cookbook and just change the one file mentioned below. I would rather not do this, however, so that I can pull in future updates to the supermarket version.

Here is what I've debugged so far:

I have noticed that the supermarket community cookbook has the following code in the octopus-deploy/libraries/tentacle.rb file:


  module OctopusDeploy
  # A container to hold the tentacle values instead of attributes
  module Tentacle
  ...
    def tentacle_install_location
      'C:\Program Files\Octopus Deploy\Tentacle'
    end

I have tried setting in my chef-repo/cookbooks/octopus-deploy-mk6/recipes/default.rb file before the install action:


    OctopusDeploy.Tentacle.tentacle_install_location = 'C:\Program Files (x86)\Octopus\Tentacle'

but it does not solve the issue. I have also tried adding an attribute to the chef-repo/cookbooks/octopus-deploy-mk6/attributes/default.rb file, but it didn't work. From my understanding this attribute file approach would only work for overriding attributes set by the other cookbook (not to override a ruby method/property).

Any help on this is appreciated. I am new to Chef and couldn't find any other posts on Stackoverflow or Google to answer this question (I may just be too new to Chef and Ruby to know the terminology to search).


Solution

  • So for the short answer: "you can't".

    To explain in more detail, we have to look at how that helper method is getting used. You could monkey patch to override that helper, the syntax would be different from what you have, but it won't help anyway so let's just move on. That method only appears to be used twice in the provider code, and both times it is to set the cwd for some snippets of PowerShell code. That path is never passed to the installer, which from what I can tell must be what is actually creating the directory. The install itself probably happens here. To change the actual install target you would need to get it into the MSI install options in that resource. I don't know Octopus Deploy specifically, but I'm guessing you can look up the needed msiexec flags to accomplish that. Unfortunately due to how this code is written, you'll have to fork the cookbook to get a change in there. I would recommend making it use a resource property and then submitting it as a patch back to the original cookbook.