I'm iterating over an array, and would like to use the key as part of the logic to lookup an Ohai value. In my particular case, I'm attempting to source
each defined user's .bashrc if triggered from a previous resource.
Ohai structure:
"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": ""
},
...
So as I loop through, I am trying to do something like:
node['my_cookbook']['managed_users'].each do |usr|
bash 'reload_shell' do
code "source #{node['etc']['passwd'][usr]['dir']}/.bashrc"
action :nothing
end
end
I've tried also using ['usr']
, [#{usr}]
, and ["usr"]
notations, as well as escaping quotes.