add user to additional groups
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.
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
Just a suggestion:
myuser:
user:
- present
- fullname: My User
- shell: /usr/bin/zsh
- home: /home/myuser
- groups:
- append:
- sudo
- adm
That would be doable, since we can check the indicies for types
i like it. don't forget a 'remove'...
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
or per option:
myuser:
user:
- present
- fullname: My User
- shell: /usr/bin/zsh
- home: /home/myuser
- groups:
- append: sudo
- remove: adm
i favor the latter one. extend_mode: append doesn't make sense for the other fields, as they are no lists.
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.
Sounds good, this will require some compiler work in the extend section, but it is very doable
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.
Thanks for the bump and the workaround! I've put this issue on the current milestone so more eyes will hopefully see it.
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?
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.
correct.
Does it remove groups if you remove a group from the original (unextended) list?
uhm, we use user;.present like this to add to groups:
foo:
user.present:
- optional_groups: [newgroup]
- remove_groups: False
(i mean this already works)
@basepi: i've added a additional group, applied state, removed it, applied state and it added/removed the group.
@pille, use remove_groups: False !!!
@kiorky: why? i'm testing what @basepi requested and it worked as expected.