salt icon indicating copy to clipboard operation
salt copied to clipboard

add user to additional groups

Open pille opened this issue 14 years ago • 25 comments

when defining a user and the groups he belongs, the groups-list is applied as expected.

myuser:                                                                                                                                                                                                              
  user:                                                                                                                                                                                                             
    - present                                                                                                                                                                                                       
    - fullname: My User                                                                                                                                                                                               
    - shell: /usr/bin/zsh                                                                                                                                                                                           
    - home: /home/myuser                                                                                                                                                                                             
    - groups:                                                                                                                                                                                                       
      - sudo                                                                                                                                                                                                        
      - adm                                                                                                                                                                                                         

myuser is in secondary groups sudo and adm.

when i want to extend that state conditionally later, i cannot specify groups to add or remove, but only overwrite that list.

extend:
  myuser:                                                                                                                                                                                                       
    user:                                                                                                                                                                                                           
      - groups:                                                                                                                                                                                                     
        - rvm                                                                                                                                                                                                       

this effectively removes the groups sudo and adm and adds rvm.

is there an easy workaround to add (and remove) secondary groups to users? i'm uncertain, if this is actually a bug report or a feature request, but i guess it's best to add a two new functions.

pille avatar Oct 01 '12 11:10 pille

Yes, this would be a feature request. Right now the extend only supports overwrites for everything except requisites. It would be worth discussing making it so that any list would append, or what syntax options we may have

thatch45 avatar Oct 01 '12 15:10 thatch45

Just a suggestion:

myuser:
  user:
    - present
    - fullname: My User
    - shell: /usr/bin/zsh
    - home: /home/myuser
    - groups:
      - append:
        - sudo
        - adm

s0undt3ch avatar Oct 02 '12 12:10 s0undt3ch

That would be doable, since we can check the indicies for types

thatch45 avatar Oct 02 '12 16:10 thatch45

i like it. don't forget a 'remove'...

pille avatar Oct 04 '12 14:10 pille

I like the direction, maybe a mode?

myuser:
  user:
    - extend_mode: append
    - present
    - fullname: My User
    - shell: /usr/bin/zsh
    - home: /home/myuser
    - groups:
      - sudo
      - adm

thatch45 avatar Oct 04 '12 16:10 thatch45

or per option:

myuser:
  user:
    - present
    - fullname: My User
    - shell: /usr/bin/zsh
    - home: /home/myuser
    - groups:
      - append: sudo
      - remove: adm

thatch45 avatar Oct 04 '12 16:10 thatch45

i favor the latter one. extend_mode: append doesn't make sense for the other fields, as they are no lists.

pille avatar Oct 04 '12 17:10 pille

I favour this one...

On 04-10-2012 17:23, Thomas S Hatch wrote:

or per option:

myuser: user: - present - fullname: My User - shell: /usr/bin/zsh - home: /home/myuser - groups: - append: sudo - remove: adm

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/2142#issuecomment-9147494.

s0undt3ch avatar Oct 04 '12 17:10 s0undt3ch

Sounds good, this will require some compiler work in the extend section, but it is very doable

thatch45 avatar Oct 04 '12 17:10 thatch45

For me, this was a show stopper. Since this issue appears to be forgotten, here's a quick workaround for Linux:

{{group}}:
  group:
    - present

usermod -a -G {{group}} {{user}}:
  cmd.run:
    - require:
      - group: {{group}}

HTH.

SaltwaterC avatar Nov 13 '13 13:11 SaltwaterC

Thanks for the bump and the workaround! I've put this issue on the current milestone so more eyes will hopefully see it.

basepi avatar Nov 14 '13 20:11 basepi

haven't been back on this for quite a time, but tried today with 2014.1 and it seems to work as expected. even if remove_groups: True (default) did the extend behavior actually change, or is this some other side-effect?

pille avatar Mar 07 '14 11:03 pille

So when you extend the state and define a group argument in that extension, it retains its previous group-list? As far as I know this hasn't been fixed, so it's possible this is a side-effect of something else or a bug. I'm not 100% sure.

basepi avatar Mar 07 '14 22:03 basepi

correct.

pille avatar Mar 08 '14 07:03 pille

Does it remove groups if you remove a group from the original (unextended) list?

basepi avatar Mar 10 '14 19:03 basepi

uhm, we use user;.present like this to add to groups:

foo:
  user.present:
    - optional_groups: [newgroup]
    - remove_groups: False

kiorky avatar Mar 11 '14 06:03 kiorky

(i mean this already works)

kiorky avatar Mar 11 '14 06:03 kiorky

@basepi: i've added a additional group, applied state, removed it, applied state and it added/removed the group.

pille avatar Mar 11 '14 08:03 pille

@pille, use remove_groups: False !!!

kiorky avatar Mar 11 '14 08:03 kiorky

@kiorky: why? i'm testing what @basepi requested and it worked as expected.

pille avatar Mar 11 '14 08:03 pille