mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Add ability for Salt States to manage groups on Windows
This commit is contained in:
parent
99ec9edd79
commit
1dc48fc940
@ -9,7 +9,7 @@ def __virtual__():
|
||||
return 'group' if __grains__['kernel'] == 'Windows' else False
|
||||
|
||||
|
||||
def add(name):
|
||||
def add(name, gid=None):
|
||||
'''
|
||||
Add the specified group
|
||||
|
||||
@ -77,6 +77,7 @@ def getent():
|
||||
salt '*' group.getent
|
||||
'''
|
||||
ret = []
|
||||
ret2 = []
|
||||
lines = __salt__['cmd.run']('net localgroup').split('\n')
|
||||
groupline = False
|
||||
for line in lines:
|
||||
@ -86,5 +87,21 @@ def getent():
|
||||
ret.append(line.strip('*').strip())
|
||||
if '---' in line:
|
||||
groupline = True
|
||||
|
||||
return ret
|
||||
for item in ret:
|
||||
members = []
|
||||
gid = __salt__['file.group_to_gid'](item)
|
||||
memberlines = __salt__['cmd.run']('net localgroup "{0}"'.format(item)).split('\n')
|
||||
memberline = False
|
||||
for line in memberlines:
|
||||
if 'successfully' in line:
|
||||
memberline = False
|
||||
if memberline:
|
||||
members.append(line.strip('*').strip())
|
||||
if '---' in line:
|
||||
memberline = True
|
||||
group = {'gid': gid,
|
||||
'members': members,
|
||||
'name': item,
|
||||
'passwd': 'x'}
|
||||
ret2.append(group)
|
||||
return ret2
|
||||
|
@ -132,6 +132,32 @@ def chprofile(name, profile):
|
||||
return post_info['profile'] == profile
|
||||
return False
|
||||
|
||||
|
||||
def chgroups(name, groups, append=False):
|
||||
'''
|
||||
Change the groups this user belongs to, add append to append the specified
|
||||
groups
|
||||
|
||||
CLI Example::
|
||||
|
||||
salt '*' user.chgroups foo wheel,root True
|
||||
'''
|
||||
if isinstance(groups, basestring):
|
||||
groups = groups.split(',')
|
||||
ugrps = set(list_groups(name))
|
||||
if ugrps == set(groups):
|
||||
return True
|
||||
if not append:
|
||||
for group in list_groups(name):
|
||||
cmd = 'net localgroup {0} {1} /delete'.format(group, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
for group in groups:
|
||||
cmd = 'net localgroup {0} {1} /add'.format(group, name)
|
||||
__salt__['cmd.run'](cmd)
|
||||
agrps = set(list_groups(name))
|
||||
return len(ugrps - agrps) == 0
|
||||
|
||||
|
||||
def info(name):
|
||||
'''
|
||||
Return user information
|
||||
|
Loading…
Reference in New Issue
Block a user