'Chef Cookbook dependency from Git repository source
I maintain a Chef Cookbook with Chef Solo to configure Vagrant VMs for development. Unfortunately, yesterday I accidentally deleted my VM and stumbled on an error. It was related to a cookbook.
==> default: ================================================================================
==> default: Recipe Compile Error in /var/chef/cache/cookbooks/givingfire/recipes/default.rb
==> default: ================================================================================
==> default:
==> default: NoMethodError
==> default: -------------
==> default: undefined method `ssl_certificate' for cookbook: givingfire, recipe: ssl :Chef::Recipe
==> default:
==> default: Cookbook Trace: (most recent call first)
==> default: ----------------------------------------
==> default: /var/chef/cache/cookbooks/givingfire/recipes/ssl.rb:1:in `from_file'
==> default: /var/chef/cache/cookbooks/givingfire/recipes/default.rb:10:in `from_file'
==> default:
==> default: Relevant File Content:
==> default: ----------------------
==> default: /var/chef/cache/cookbooks/givingfire/recipes/ssl.rb:
==> default:
==> default: 1>> cert = ssl_certificate node['ssl']['name'] do
==> default: 2: namespace node['ssl']
==> default: 3: end
==> default: 4:
==> default: 5: log "#{node['ssl']['name']} certificate is here: #{cert.cert_path}"
==> default: 6: log "#{node['ssl']['name']} private key is here: #{cert.key_path}" 7:
When I looked into the cookbook issues, I found an open issue and a PR related to it.
The issue with PR: https://github.com/zuazo/ssl_certificate-cookbook/pull/46
My question is: Is there a way we can specify a cookbook as a dependency based on a Git repository. Ideally, something like we do in a Gemfile by specifying the source and branch. Unfortunately, the documentation provides no hints, and I suspect it's not supported. Anyways I tried with no success.
# File: metadata.rb
depends 'ssl_certificate', '~> 2.1.0', git: 'https://github.com/vzDevelopment/ssl_certificate-cookbook.git', branch: 'add_provider-issue_45'
Any suggestion as to how I might use the GitHub repository as a source for the dependency?
Solution 1:[1]
Assuming you are not using Policyfiles for managing your dependencies:
In your metadata.rb file:
depends 'ssl_certificate', '~> 2.1.0'
Add this line to your Berksfile file:
cookbook 'ssl_certificate', git: 'https://github.com/vzDevelopment/ssl_certificate-cookbook.git', branch: 'add_provider-issue_45'
If you are using Policyfiles, then instead of creating / modifing the Berksfile file, add that line to your Policyfile.rb file
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | trickyslip |
