vskubriev
vskubriev

Reputation: 858

How to create a user and group in chef without 'cloning resource' warning

I recently used following recipe to create a specific user, group:

sysadmin = data_bag_item('users','sysadmin')

group 'sysadmin' do
  action :create
  gid sysadmin['gid'].to_i
end

user 'sysadmin' do
  uid sysadmin['uid'].to_i
  gid sysadmin['gid'].to_i
  manage_home true
  shell sysadmin['shell']
  action :create
end

group 'sysadmin' do
  action :modify
  members 'sysadmin'
  append true
end

And get following warnings:

  Cloning resource attributes for group[sysadmin] from prior resource
Previous group[sysadmin]: /var/chef/cache/cookbooks/initialubuntu/recipes/sysadmin_user.rb:16:in `from_file'
Current  group[sysadmin]: /var/chef/cache/cookbooks/initialubuntu/recipes/sysadmin_user.rb:29:in `from_file' at 1 location:

Chef cannot create a user with gid of non-existent system group.

How to merge group resources into one?

Upvotes: 1

Views: 1394

Answers (1)

coderanger
coderanger

Reputation: 54211

You would have to rename one of them, for example you could rename the second one:

group 'append sysadmin' do
  group_name 'sysadmin'
  action :modify
  members 'sysadmin'
  append true
end

Alternatively if you upgrade to Chef 13, cloning has been removed at long last so these warnings are impossible now.

Upvotes: 1

Related Questions