如何让 Ohai Plugin 产生 ['etc']['passwd']?

How to enable Ohai Plugin to produce ['etc']['passwd']?

我已将我的 Chef Client 从 14.0 升级到 15.3.14,但每当我在我的节点 (macOS Mojave) 上执行 chef-client 时问题就会增加。
客户端输出为:

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

Cookbook Trace:
---------------
  /var/chef/cache/cookbooks/macos/recipes/mac_init.rb:62:in `from_file'

Relevant File Content:
----------------------
/var/chef/cache/cookbooks/macos/recipes/mac_init.rb:

 55:    action :create
 56:    owner 'administrator'
 57:    group 'localaccounts'
 58:    mode  '0775'
 59:  end
 60:
 61:  # Template for bash history
 62>>   node['etc']['passwd'].each do |user, data|
 63:
 64:    template "/Users/#{user}/.bash_profile" do
 65:      source '/default/bash_profile.erb'
 66:      owner 'administrator'
 67:      group 'staff'
 68:      ignore_failure true
 69:    end
 70:  end

似乎 node['etc']['passwd'] 不再可读,结果的值为 nil
我已经检查了另一台新引导的机器,并在 Chef Server UI 上对其进行了验证,但结果是,属性选项卡中没有 'etc'。

阅读 release notes of ohai 它说:

Optional Ohai Plugins

Ohai now includes the ability to mark plugins as optional, which skips those plugins by default. This allows us to ship additional plugins, which some users may find useful, but not all users would want being written to their Chef server. The change introduces two new configuration options; run_all_plugins which runs everything including optional plugins, and optional_plugins which allows you to run plugins marked as optional.

By default we will now be marking the lspci, sessions and passwd plugins as optional. Passwd has been particularly problematic for nodes attached LDAP or AD where it attempts to write the entire directory to the node. If you previously disabled this plugin via Ohai config, you no longer need to. Hurray!

但你总是可以 enable back the optional plugins:

Enabling Optional Plugins

Optional plugins can be enabled in the client.rb configuration file: ohai.optional_plugins = [ :Sessions, :Lspci ]

在您的具体情况下:

ohai.optional_plugins = [
  :Passwd
]

假设您使用 bundler 安装了 ohai,那么您可以通过执行

检查 passwd 是否存在
$ bundle exec ohai etc

配置

经常有这样的行为,那么:

  • 如果chef-zero is used when invoking chef-client, client.rb可以使用,可以存储在仓库中。
  • 使用ohai resource。就像是:
    ohai 'reload_passwd' do
      action :reload
      plugin 'etc'
    end
    
  • chef-client cookbook 做出贡献,以获得对 node['ohai']['disabled_plugins']
  • 的免费支持

更新: 对此的支持已引入 chef-client cookbook:

  • node['ohai']['disabled_plugins'] - An array of ohai plugins to disable, empty by default, and must be an array if specified. Ohai 6 plugins should be specified as a string (ie. "dmi"). Ohai 7+ plugins should be specified as a symbol within quotation marks (ie. ":Passwd").
  • node['ohai']['optional_plugins'] - An array of optional ohai plugins to enable, empty by default, and must be an array if specified. Ohai 6 plugins should be specified as a string (ie. "dmi"). Ohai 7+ plugins should be specified as a symbol within quotation marks (ie. ":Passwd").