2013-08-19 34 views
3

我遵循this post中描述的方法来创建新服务器的DNS记录,因为厨师提供了它。我创建了一个加密的数据包项目为我的AWS凭据:EncryptedDataBagItem.load产生'不能将零转换为字符串'

$ knife data bag show passwords aws --secret-file .chef/encryted_data_bag_secret 
aws_access_key: <my_access_key> 
aws_secret_key: <my_secret_key> 
id:    aws 

然而,当我运行厨师客户端,这条线......

aws_creds = Chef::EncryptedDataBagItem.load('passwords', 'aws') 

产生这个错误:

TypeError: can't convert nil into String 

我试过寻找错误,但虽然我可以看到其他人遇到过这种情况的证据,但不清楚他们的问题是什么或者它是如何解决的。这里发生了什么,我该如何解决它?

回答

4

我今天也遇到这个错误。对我来说,节点缺少encrypted_data_bag_secret。

根据这个bug(http://tickets.opscode.com/browse/CHEF-4441),错误(对我来说)将在厨师11.4.4已经更加清晰:

No such file or directory - file not found '/etc/chef/encrypted_data_bag_secret' 

我希望这是有帮助的。

+1

这绝对是问题的一部分。我有一个可以复制秘密文件的配方(早于run_list),但显然,在chef-client开始运行*之前,关键文件需要到位。 – MrTheWalrus

1

关于食谱的执行顺序,(对rgnever的回答发表评论)你是正确的,有些事情看起来是不按顺序发生的。下面是一个Opscode article on Chef Recipe execution

Chef processes recipes in two phases, Compile and Execute.

  1. During the compile phase, the recipes are evaluated as Ruby code and recognized resources are added to the resource collection.
  2. During the execute phase, Chef takes the appropriate Provider action on each resource.

我还没有找到明确证实了这一文件,但行为显然是数据包是在编译时,就会执行这个一个这样的资源类型。因此,你的配方的这一部分实际上会破坏运行列表的顺序,跳过其他必须在秘密文件中加载的其他配方。

我们能够通过使用该文档中描述的技巧(适应于cookbook_file资源)解决此问题。

cb_file = cookbook_file "/etc/chef/encrypted_data_bag_secret" do 
    source "chef_secret_file" 
    mode 0755 
    owner "root" 
    group "root" 
end 

cb_file.run_action(:create) 

注意,:nothing行动不支持cookbook_file resource,缺乏资源块的动作有将默认:create,这在配方的执行阶段实际上将覆盖你的秘密文件好。