sous-chefs / users

Development repository for the users cookbook
https://supermarket.chef.io/cookbooks/users
Apache License 2.0
138 stars 218 forks source link

undefined method `validate_id' for Chef::Resource::Group #406

Closed ghost closed 6 years ago

ghost commented 7 years ago

Cookbook version

5.1.0

Chef-client version

12.6

Platform Details

RHEL 7.3

Scenario:

Running the recipe to create the group/user produces the error: undefined method `validate_id' for Chef::Resource::Group

Steps to Reproduce:

I have a simple data bag called "users" created and uploaded to the Chef Server:

{
  "id"       : "user1",
  "comment"  : "User One",
  "home"     : "/home/user1",
  "groups"   : ["devops"],
  "ssh_keys" : [
     "2048 65537.... GX270"
  ]
}

And then a simple cookbook:

Added to metadata.rb: depends 'users'

recipe:

users_manage 'devops' do
  action [ :remove, :create ]
end

Expected Result:

Group "devops" and user "user1" created when running chef-client on node

Actual Result:

chef-client produces this error: Synchronizing Cookbooks:

ghost commented 7 years ago

I fixed this issue by adding this to the top of my recipe: Chef::Resource.send(:include, Users::Helpers)

A new error then occurred: No resource or method named manage_home_files?' forCustom resource users_manage from cookbook users action provider "usertest"'

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/users/resources/manage.rb:83:in `block (2 levels) in class_from_file'
/var/chef/cache/cookbooks/users/resources/manage.rb:36:in `block in class_from_file'

Added class_eval back and now it works:

action_class.class_eval do
  include ::Users::Helpers
  include ::Users::OsxHelper

  def manage_home_files?(home_dir, _user)
    # Don't manage home dir if it's NFS mount
    # and manage_nfs_home_dirs is disabled
    if home_dir == '/dev/null'
      false
    elsif fs_remote?(home_dir)
      new_resource.manage_nfs_home_dirs ? true : false
    else
      true
    end
  end
end

Everything works now, but I am sure that with my very limited knowledge of ruby and chef libraries, what I have done could be very dangerous :)

iennae commented 7 years ago

What happens if the only change you make is to add the class_eval back? The current cookbook is pinned to Chef versions higher than 12.7 because we removed the class_eval. The class_eval is required so the cookbook can work with 12.5-12.6, but also breaks newer versions of Chef 12. Our policy is to support at minimum the last 6 months of Chef versions which is why we've removed class_eval. If doing that works, you may want to pin your cookbook version back a few revisions (or optimally update your chef client to a newer 12.X version.)

iennae commented 6 years ago

@kosie99 I've given you the mechanism to get this working in my previous comment. If that doesn't work for you please reopen with additional details. Thanks!