我目前正在使用Chef supermarket Jenkins cookbook来部署Jenkins实例。我正在尝试在_master_war_.rb配方文件中配置jenkins实例时启用安全性。 Code to enable security and create a user using an RSA key如下:
require 'openssl'
require 'net/ssh'
unless node.run_state[:jenkins_private_key]
# defaults to /etc/chef-jenkins-api.key
key_path = node['jenkins_chefci']['jenkins_private_key_path']
begin
Chef::Log.info 'Trying to read private key from ' + key_path + ' for the chef user in jenkins'
key = OpenSSL::PKey::RSA.new File.read(key_path)
Chef::Log.info 'Successfully read existing private key'
rescue
key = OpenSSL::PKey::RSA.new 2048
Chef::Log.info 'Generating new key pair for the chef user in jenkins in ' + key_path
file key_path do
content key.to_pem
mode 0500
sensitive true
end
end
public_key = [key.ssh_type, [key.to_blob].pack('m0'), 'auto-generated key'].join(' ')
# Create the Jenkins user with the public key
jenkins_user 'chef' do
id 'chef@' + Chef::Config[:node_name]
full_name 'Chef Client'
public_keys [public_key]
end
# Set the private key on the Jenkins executor
node.run_state[:jenkins_private_key] = key.to_pem
end
当我尝试在受管节点上的运行列表中应用此配方时,收到以下错误:
NoMethodError
-------------
undefined method `[]' for nil:NilClass
stacktrace表示错误与我的配方文件中的特定代码行有关:
>> key_path = node['jenkins_chefci']['jenkins_private_key_path']
我已经看到了这个错误(未定义的方法`[]'对于nil:NilClass),相当多的在线,但是无法缩小我的食谱中的根本原因。我的食谱文件中可能遗漏了什么吗?我想知道错误的根本原因是否与这两行有关:
require 'openssl'
require 'net/ssh'