Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #755 from UtahDave/develop

Add ability for Salt States to manage groups on Windows
  • Loading branch information...
commit c9aa48abb9c390977ee3b4149549ec38b7cb799a 2 parents 99ec9ed + 1dc48fc
@thatch45 thatch45 authored
Showing with 46 additions and 3 deletions.
  1. +20 −3 salt/modules/win_groupadd.py
  2. +26 −0 salt/modules/win_useradd.py
View
23 salt/modules/win_groupadd.py
@@ -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
View
26 salt/modules/win_useradd.py
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.