简体   繁体   中英

chef: ohai does not provide node['etc']

I had a requirment to do a certain action only given that a specific user exists. Looking at the following question Chef Users resource (check if exists?) I concluded that the following:

if node['etc']['passwd']['random']

would be a good method.

This actually worked when I tested it in kitchen, but when pushed to production this crushed on all servers with the error:

NoMethodError: undefined method `[]' for nil:NilClass

When using ohai from bash I do see etc: {...}

What exactly is happening here?

Eventually, with the help of the people in the comments, I have found that the Ohai passwd plugin was in fact disabled. Due to that, I had to work around the problem and query the existence of a user like so:

if 'grep td-agent /etc/passwd > /dev/null; echo $?' == '0'

Finally, for future reference, my entire resource:

group 'groupname' do
  action :create
  members 'td-agent' if 'grep td-agent /etc/passwd > /dev/null; echo $?' == '0'
  append true
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM