rubyapachechef-infrachef-recipeohai-gem

Chef Apache2 recipe failing during server build


I've been rebuilding our Chef master server to run in a T2 instance, which means moving it into a VPC. The old master is running 11.10.4 and the new one I've been tinkering with is running 11.16.4. I've gotten close to having it build a proper server within the VPC but it gets hung up setting up Apache.

ohai[reload_users] action reload[2014-11-25T08:13:58-06:00] ERROR: Encountered error while running plugins: #<Ohai::Exceptions::AttributeNotFound : No such attribute: 'passwd'

Specifically it doesn't seem to like this code in the recipe

if node[:etc][:passwd][:apache] == nil
    ohai "reload_users" do
        plugin "passwd"
        action :reload
    end
end

I've looked around and found this article on ohai

In Ohai 6 passwd plugin (named passwd.rb) sets the 'current_user' attribute and in order to use this data one needs to know this fact.
require_plugin("passwd")

With Ohai 7, user interaction is now based on the attribute names. Only specify the names of the attributes for which you would like to collect data. Ohai 7 figures out which plugins are required and then collects the data.

In Ohai 7 one doesn't need to know the underlying details to find out current_user
depends 'currentuser'

Looks close... but it fails if I replace plugin "passwd" with depends 'currentuser' it also fails.

I think I'm using Ohai 7 (gem list shows ohai (7.4.0)). I'm not a ruby guy so it's a bit fuzzy there. What exactly is this code supposed to be doing? This is custom added to the repo from the old Opscode cookbooks. Our cookbook was written largely by someone else who no longer works for our company and doesn't know the answer to this either. If I comment it out it works just fine and installs Apache but I would be remiss to just delete some code without understanding it.


Solution

  • With OHAI 7, you don't need (and can't) reload plugins on the basis of the filename where the specific function is provided. Instead, you reload it based on the specific attribute you want to reload.

    Thus, while the attributes in node['etc']['passwd'] still are provided by a plugin named passwd.rb, you can't reload it that way. Instead, you want to reload the data in node['etc'], regardless from which files it is filled.

    You can reload the password data by using this code in your recipe:

    ohai "reload_users" do
      plugin "etc"
      action :reload
    end
    

    This is taken from the documentation at https://docs.getchef.com/ohai.html#id3.