Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change group for user_install #242

Closed
Doltair opened this issue Jan 28, 2019 · 5 comments
Closed

change group for user_install #242

Doltair opened this issue Jan 28, 2019 · 5 comments

Comments

@Doltair
Copy link

Doltair commented Jan 28, 2019

Cookbook version

2.1.2

Chef-client version

14.4.56

Platform Details

Rhel 7

Scenario:

property :group, String, default: lazy { user }

Is it possible that it can have a feature for custom group? it seems that it defaults to user.
The case is what if we want to use rbenv on a user:chefadmins instead of user:user

@Doltair
Copy link
Author

Doltair commented Jan 28, 2019

 49:   git new_resource.user_prefix do
       50:     repository new_resource.git_url
       51:     reference new_resource.git_ref
       52:     action :checkout if new_resource.update_rbenv == false
       53:     user new_resource.user
       54:     group new_resource.group <=== not working if custom group is specified
       55:     notifies :run, 'ruby_block[Add rbenv to PATH]', :immediately
       56:   end
       57: 

@damacus damacus mentioned this issue Jan 30, 2019
3 tasks
@damacus
Copy link
Member

damacus commented Jan 30, 2019

I've confirmed with inspec that this isn't the case. So I'm a little confused how you're setting the value!

See this test for how I'm setting the group: https://github.com/sous-chefs/ruby_rbenv/pull/245/files#diff-2f1fd653c59c431dfe5f42fd9c8c5fdc

And here for me testing for the correct group: https://github.com/sous-chefs/ruby_rbenv/pull/245/files#diff-817b63b0dbded23627f5495795b18289

@damacus damacus closed this as completed Jan 30, 2019
@Doltair
Copy link
Author

Doltair commented Jan 30, 2019

Hi @damacus

thank you so much for taking this for a review.

My case was the group of the user is different and they are not alike. E.g vagrant:adminuser not vagrant:vagrant

Here are my concerns: let me know if i am using the resource correctly

But i want is:

ruby_rbenv resource

rbenv_user_install 'appuser' do
  user 'appuser'
  group 'appuserdifferentgroup' <== need to override. Group is not the same as user
end

for what's happening: The output of that resource becomes

rbenv_user_install 'appuser' do
  user 'appuser'
  group 'appuser' <== thinking because of the default value in the custom resources under user_install
end

Im using these resource and needing it to override the group as there are cases that user and group are not the same:

# Keeps the rbenv install upto date
node.default['webhook_api']['app_username'] = node['webhook_api']['special_account']['user'] if node['webhook_api']['special_account_enable'] == true
rbenv_user_install(node['webhook_api']['app_username']).to_s do
  user(node['webhook_api']['app_username']).to_s
  group node['webhook_api']['app_username'] if node['webhook_api']['special_account_enable'] == false
  group node['webhook_api']['special_account']['group'] if node['webhook_api']['special_account_enable'] == true
end

in my case if the service account group is available in the node, it should override the group. if false, it will use the normal user which has the same group as user.

e.g

if service account user set to false, my cookbook will create a new user like webhook_admin:webhook_admin
if service account set to true, it will use a different attribute and use the service account user like serviceaccountuser:serviceaccountgroup which user:group are not alike.

@Doltair
Copy link
Author

Doltair commented Jan 31, 2019

Hi @damacus,

Still not working, the cookbook can't see ldap group even its specified on resource rbenv_user_install. the group that stated in

rbenv_user_install 'apiuser' do
  user 'apiuser'
  group 'apiadmins'
end 

And then throws me an exception below, and it seems the resource still using the user as the the group

  ================================================================================
    Error executing action `sync` on resource 'git[/home/apiuser/.rbenv]'
    ================================================================================
    
    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0, 128], but received '1'
    ---- Begin output of git rev-parse HEAD ----
    STDOUT: 
    STDERR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout.rb:220:in `getgrnam': can't find group for apiuser (ArgumentError)
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout.rb:220:in `gid'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:162:in `set_group'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:333:in `block in fork_subprocess'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:318:in `fork'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:318:in `fork_subprocess'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:95:in `run_command'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout.rb:267:in `run_command'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/mixin/shell_out.rb:234:in `shell_out_command'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/mixin/shell_out.rb:200:in `shell_out_compacted!'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/mixin/shell_out.rb:124:in `shell_out!'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider/git.rb:338:in `git'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider/git.rb:137:in `find_current_revision'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider/git.rb:38:in `load_current_resource'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider.rb:165:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource.rb:578:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:70:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `block (2 levels) in converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `each'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `block in converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:97:in `converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider.rb:237:in `compile_and_converge_action'
      from (eval):2:in `action_install'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/provider.rb:182:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource.rb:578:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:70:in `run_action'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `block (2 levels) in converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `each'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:98:in `block in converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/resource_list.rb:94:in `block in execute_each_resource'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:114:in `call_iterator_block'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:103:in `iterate'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/resource_collection/resource_list.rb:92:in `execute_each_resource'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/runner.rb:97:in `converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/client.rb:720:in `block in converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/client.rb:715:in `catch'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/client.rb:715:in `converge'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/client.rb:754:in `converge_and_save'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/client.rb:286:in `run'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:321:in `block in fork_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:309:in `fork'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:309:in `fork_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:274:in `block in run_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/local_mode.rb:44:in `with_server_connectivity'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:261:in `run_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application/client.rb:475:in `sleep_then_run_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application/client.rb:464:in `block in interval_run_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application/client.rb:463:in `loop'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application/client.rb:463:in `interval_run_chef_client'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application/client.rb:447:in `run_application'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/lib/chef/application.rb:66:in `run'
      from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/chef-14.7.17/bin/chef-client:25:in `<top (required)>'
      from /bin/chef-client:74:in `load'
      from /bin/chef-client:74:in `<main>'
    ---- End output of git rev-parse HEAD ----
    Ran git rev-parse HEAD returned 1
    
    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/ruby_rbenv/resources/user_install.rb
    
     49:   git new_resource.user_prefix do
     50:     repository new_resource.git_url
     51:     reference new_resource.git_ref
     52:     action :checkout if new_resource.update_rbenv == false
     53:     user new_resource.user
     54:     group new_resource.group
     55:     notifies :run, 'ruby_block[Add rbenv to PATH]', :immediately
     56:   end
     57: 
    
    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/ruby_rbenv/resources/user_install.rb:49:in `block in class_from_file'
    
    git("/home/apiuser/.rbenv") do
      action [:sync]
      default_guard_interpreter :default
      declared_type :git
      cookbook_name "does_api_server"
      repository "https://github.com/rbenv/rbenv.git"
      revision "master"
      user "apiuser"
      group "apiuser"
      destination "/home/apiuser/.rbenv"
      additional_remotes {}
    end
    
    System Info:
    ------------
    chef_version=14.7.17
    platform=redhat
    platform_version=7.4
    ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
    program_name=chef-client worker: ppid=59171;start=08:19:18;
    executable=/opt/chef/bin/chef-client
    
[2019-01-31T08:19:26-06:00] INFO: Running queued delayed notifications before re-raising exception
  
  ================================================================================
  Error executing action `install` on resource 'ruby_rbenv_user_install[apiuser]'
  ================================================================================
  
  Mixlib::ShellOut::ShellCommandFailed
  ------------------------------------
  git[/home/apiuser/.rbenv] (/var/chef/cache/cookbooks/ruby_rbenv/resources/user_install.rb line 49) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0, 128], but received '1'
  ---- Begin output of git rev-parse HEAD ----
  STDOUT: 
  STDERR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout.rb:220:in `getgrnam': can't find group for apiuser (ArgumentError)
    from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout.rb:220:in `gid'
    from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:162:in `set_group'
    from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:333:in `block in fork_subprocess'
    from /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/mixlib-shellout-2.4.0/lib/mixlib/shellout/unix.rb:318:in `fork'

Although it works if i remove this:

 default: lazy { user } from
property :group,        String, default: lazy { user }

To become:

property :group,        String

@lock
Copy link

lock bot commented Aug 8, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants