ssl_certificate-cookbook
ssl_certificate-cookbook copied to clipboard
Compilation fails when using Chef Client 16.1.16
Cookbook Version
2.1.0
Chef Client Version
16.1.16
Platform Details
Centos 7.8
Scenario
Recipe compilation
Steps to Reproduce
Add the ssl_certificate dependency, add the snippet below in a recipe, and then converge it.
cert = ssl_certificate 'webapp1' do
namespace node['webapp1'] # optional but recommended
end
Expected Result
Compiles successfully
Actual Result
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/parent-cookbook/recipes/default.rb
================================================================================
NoMethodError
-------------
undefined method `ssl_certificate' for cookbook: child-cookbook, recipe: default :Chef::Recipe
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/child-cookbook/recipes/default.rb:9:in `from_file'
/tmp/kitchen/cache/cookbooks/parent-cookbook/recipes/default.rb:12:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/child-cookbook/recipes/default.rb:
2: # Cookbook Name:: child-cookbook
3: # Recipe:: default
4: #
5: # Copyright (c) 2016 The Authors, All Rights Reserved.
6: # include_recipe '****-sshd::default'
7: #
8:
9>> cert = ssl_certificate 'proftpd' do
10: common_name node['child-cookbook']['public-name']
11: end
System Info:
------------
chef_version=16.1.16
platform=centos
platform_version=7.8.2003
ruby=ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
program_name=/opt/chef/bin/chef-solo
executable=/opt/chef/bin/chef-solo
Running handlers:
[2020-06-10T18:19:53+00:00] ERROR: Running exception handlers
Running handlers complete
[2020-06-10T18:19:53+00:00] ERROR: Exception handlers complete
Chef Infra Client failed. 0 resources updated in 10 seconds
[2020-06-10T18:19:53+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out
[2020-06-10T18:19:53+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2020-06-10T18:19:53+00:00] FATAL: NoMethodError: undefined method `ssl_certificate' for cookbook: child-cookbook, recipe: default :Chef::Recipe
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>> Converge failed on instance <default-centos-78>. Please see .kitchen/logs/default-centos-78.log for more details
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration
I think this might be because "HWRP Style Resources Now Require resource_name / provides" in Chef 16 (source). I've never written an HWRP before, but following this as a reference and adding:
diff --git a/libraries/resource_ssl_certificate.rb b/libraries/resource_ssl_certificate.rb
index 69b27b1..3b48233 100644
--- a/libraries/resource_ssl_certificate.rb
+++ b/libraries/resource_ssl_certificate.rb
@@ -58,6 +58,8 @@ class Chef
# Include methods related to PKCS12 attributes.
include ::Chef::Resource::SslCertificate::PKCS12
+ provides :ssl_certificate
+
def initialize(name, run_context = nil)
super
@resource_name = :ssl_certificate
It no longer throws this error. I'm just running it through the kitchen test suite now and if that looks good I'll submit a PR.
@vzDevelopment Is there a way we can add a dependency through git? I have something like this in my metadata.rb.
# metadata.rb
depends 'ssl_certificate', '~> 2.1.0'
You may be able to replace your usage of ssl_certificate with openssl_x509_certificate that shipped with Chef Infra Client starting in v14.4. The properties may be named slightly different, but functionally it should serve the same purpose, avoiding this issue with Chef Infra Client v16+.