我正在遍历一个数组,并希望使用该键作为逻辑的一部分来查找 Ohai 值。source
在我的特殊情况下,如果从以前的资源触发,我会尝试每个定义的用户的 .bashrc。
欧海结构:
"etc": {
"passwd": {
"root": {
"dir": "/root",
"gid": 0,
"uid": 0,
"shell": "/bin/bash",
"gecos": "root"
},
...
"foo": {
"dir": "/home/foo",
"gid": 501,
"uid": 501,
"shell": "/bin/bash",
"gecos": ""
},
...
因此,当我遍历时,我正在尝试执行以下操作:
node['my_cookbook']['managed_users'].each do |usr|
bash 'reload_shell' do
code "source #{node['etc']['passwd'][usr]['dir']}/.bashrc"
action :nothing
end
end
我也尝试过使用['usr']
,[#{usr}]
和["usr"]
符号,以及转义引号。