我有以下方法将一些数据写入用户主目录chef中的文件中。current如您所见,vagrant在我的例子中,用户是硬编码的。我必须做什么才能使代码user根据当前登录的人动态获取?
file '/home/vagrant/.ssh/id_rsa' do
content "This is the super secret"
mode '0755'
owner 'vagrant'
group 'vagrant'
end
Run Code Online (Sandbox Code Playgroud)
我尝试做类似以下的事情,但它不起作用:
file '/home/#{node['user']}/.ssh/id_rsa'
在几乎所有情况下chef-client或 都chef-solo以 root 身份运行,无论是作为系统服务还是通过sudo. 如果这是为了在 Test Kitchen 中设置测试环境,只需进行硬编码即可。如果这是用于工作站设置,那么您可以在 中找到用户名ENV['USER']。