Closed ghost closed 6 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?' for
Custom 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 :)
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.)
@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!
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:
And then a simple cookbook:
Added to metadata.rb:
depends 'users'
recipe:
Expected Result:
Group "devops" and user "user1" created when running chef-client on node
Actual Result:
chef-client produces this error: Synchronizing Cookbooks:
users_manage[devops] action create
Error executing action
create
on resource 'users_manage[devops]'NoMethodError
undefined method `validate_id' for Chef::Resource::Group
Cookbook Trace:
/var/chef/cache/cookbooks/users/resources/manage.rb:63:in
block (3 levels) in class_from_file' /var/chef/cache/cookbooks/users/resources/manage.rb:58:in
block (2 levels) in class_from_file' /var/chef/cache/cookbooks/users/resources/manage.rb:36:in `block in class_from_file'