Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make newly created user as sudo user by using chef

I have created a user 'testuser' by using chef. How to make this user as sudo user?

like image 211
Sampath Avatar asked Feb 07 '17 15:02

Sampath


3 Answers

There is a way to modify sudo group by using group resource:

group "create testuser sudo" do
  group_name 'sudo'
  members 'testuser'
  action :modify
  append true
end

Another way is to use sudo recipe https://supermarket.chef.io/cookbooks/sudo .

Recommended way to me is to go with the sudo recipe and offload system specific logic to recipe. There you get attributes resource configurations that makes you recipe code robust.

like image 107
gsone Avatar answered Nov 01 '22 12:11

gsone


There's an existing sudo cookbook for managing this.

There's a sudo LWRP that will then allow you to add a user (it will add file to the /etc/sudoers.d directory)

sudo 'tomcat' do
  user      "%tomcat"    # or a username
  runas     'app_user'   # or 'app_user:tomcat'
  commands  ['/etc/init.d/tomcat restart']
end
like image 35
Mark Unsworth Avatar answered Nov 01 '22 13:11

Mark Unsworth


You do it the same way as always, by adding the user to your /etc/sudoers config. You could manage that file using a template resource, for example.

like image 35
coderanger Avatar answered Nov 01 '22 12:11

coderanger