How to make newly created user as sudo user by using chef
Asked Answered
P

4

6

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

Paroicous answered 7/2, 2017 at 15:22 Comment(2)
Welcome to Stackoverflow. What code have you tried so far?Dilan
Try searching sudo in supermarket.chef.io ?Presbyterial
K
6

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.

Karb answered 16/2, 2017 at 3:15 Comment(1)
Thanks for your Ans. I have tested this and it worked for me:-)Paroicous
D
3

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
Decadence answered 10/2, 2017 at 16:47 Comment(0)
S
2

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.

Sumrall answered 7/2, 2017 at 20:5 Comment(0)
P
0

Since Chef 14, 'sudo' is a resource

Pomerleau answered 7/11, 2018 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.