【发布时间】:2015-06-30 16:36:56
【问题描述】:
我正在遍历一个数组,并希望使用该键作为逻辑的一部分来查找 Ohai 值。在我的特殊情况下,如果从以前的资源触发,我会尝试 source 每个定义的用户的 .bashrc。
Ohai 结构:
"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"] 符号,以及转义引号。
【问题讨论】:
标签: loops attributes chef-infra ohai-gem