Ruby 在template.erb中设置chef vault变量
我的配方中定义了一个保险库项目,如下所示Ruby 在template.erb中设置chef vault变量,ruby,chef-infra,cookbook,Ruby,Chef Infra,Cookbook,我的配方中定义了一个保险库项目,如下所示 item = ChefVault::Item.load("user","password") 在我的模板.erb中该如何称呼它?我尝试了以下不起作用的方法 ROOTPASSWORD= <%= @node["testcookbook"]["user"]["password"] %> 我通常在食谱中做类似的事情 ROOTPASSWORD #{item['pass']} 但是,我认为这在模板中是行不通的。有两种方法可以解决这个问题,尽管第二种
item = ChefVault::Item.load("user","password")
在我的模板.erb
中该如何称呼它?我尝试了以下不起作用的方法
ROOTPASSWORD= <%= @node["testcookbook"]["user"]["password"] %>
我通常在食谱中做类似的事情
ROOTPASSWORD #{item['pass']}
但是,我认为这在模板中是行不通的。有两种方法可以解决这个问题,尽管第二种方法应该是首选的,因为它可以使敏感数据保持私有 假设,如果您的vault如下所示:
$ knife vault show user password
id: password
pass: xxxxxxxxxx
username: chefuser
knife vault show user password
id: password
pass: xxxxxxxxxx
username: chefuser
然后,您可以采用以下方法:
另存为节点属性
首先,如果要在节点对象上设置密码并使其可见,则
您可以执行以下操作:
在配方中:
node.default["testcookbook"]["user"]["password"] = ChefVault::Item.load("user","password")['pass']
template '/tmp/template' do
source 'template.erb'
owner 'root'
group 'root'
mode '0644'
end
在模板中:
ROOTPASSWORD= <%= node["testcookbook"]["user"]["password"] %>
ROOTPASSWORD= <%= @password %>
在模板中:
ROOTPASSWORD= <%= node["testcookbook"]["user"]["password"] %>
ROOTPASSWORD= <%= @password %>
ROOTPASSWORD=
感谢您花时间用代码解释。我强烈支持第二种选择。如果将其另存为节点属性,则无需将其保存在chef vault中。完全同意!很高兴听到。我建议在你的帖子中进一步澄清这一点。人们可能会在没有思考或阅读下面的讨论的情况下复制并粘贴这些内容。顺便说一句,你可以通过以下方式表明你的共识。谢谢你,Mrigesh-为了清晰起见,我编辑了最初的问题。@jebjeb-更新了解决方案。