mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
Merge branch 'osx_user_fix' of https://github.com/bambou42/ansible-modules-core into bambou42-osx_user_fix
Includes commits for: * Don't return change if the password is not set * Set the group to nogroup if none is specified * Set an uid if none is specified * Test if SHADOWFILE is set (for Darwin) * remove unused uid
This commit is contained in:
parent
cf61778689
commit
68a07a2bb5
1 changed files with 30 additions and 10 deletions
|
@ -547,7 +547,7 @@ class User(object):
|
||||||
return passwd
|
return passwd
|
||||||
if not self.user_exists():
|
if not self.user_exists():
|
||||||
return passwd
|
return passwd
|
||||||
else:
|
elif self.SHADOWFILE:
|
||||||
# Read shadow file for user's encrypted password string
|
# Read shadow file for user's encrypted password string
|
||||||
if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK):
|
if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK):
|
||||||
for line in open(self.SHADOWFILE).readlines():
|
for line in open(self.SHADOWFILE).readlines():
|
||||||
|
@ -1424,6 +1424,24 @@ class DarwinUser(User):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _get_next_uid(self):
|
||||||
|
'''Return the next available uid'''
|
||||||
|
cmd = self._get_dscl()
|
||||||
|
cmd += ['-list', '/Users', 'UniqueID']
|
||||||
|
(rc, out, err) = self.execute_command(cmd)
|
||||||
|
if rc != 0:
|
||||||
|
self.module.fail_json(
|
||||||
|
msg="Unable to get the next available uid",
|
||||||
|
rc=rc,
|
||||||
|
out=out,
|
||||||
|
err=err
|
||||||
|
)
|
||||||
|
max_uid = 0
|
||||||
|
for line in out.splitlines():
|
||||||
|
if max_uid < int(line.split()[1]):
|
||||||
|
max_uid = int(line.split()[1])
|
||||||
|
return max_uid + 1
|
||||||
|
|
||||||
def _change_user_password(self):
|
def _change_user_password(self):
|
||||||
'''Change password for SELF.NAME against SELF.PASSWORD.
|
'''Change password for SELF.NAME against SELF.PASSWORD.
|
||||||
|
|
||||||
|
@ -1449,7 +1467,8 @@ class DarwinUser(User):
|
||||||
|
|
||||||
def _make_group_numerical(self):
|
def _make_group_numerical(self):
|
||||||
'''Convert SELF.GROUP to is stringed numerical value suitable for dscl.'''
|
'''Convert SELF.GROUP to is stringed numerical value suitable for dscl.'''
|
||||||
if self.group is not None:
|
if self.group is None:
|
||||||
|
self.group = 'nogroup'
|
||||||
try:
|
try:
|
||||||
self.group = grp.getgrnam(self.group).gr_gid
|
self.group = grp.getgrnam(self.group).gr_gid
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -1512,7 +1531,6 @@ class DarwinUser(User):
|
||||||
plist_file = '/Library/Preferences/com.apple.loginwindow.plist'
|
plist_file = '/Library/Preferences/com.apple.loginwindow.plist'
|
||||||
|
|
||||||
# http://support.apple.com/kb/HT5017?viewlocale=en_US
|
# http://support.apple.com/kb/HT5017?viewlocale=en_US
|
||||||
uid = int(self.uid)
|
|
||||||
cmd = [ 'defaults', 'read', plist_file, 'HiddenUsersList' ]
|
cmd = [ 'defaults', 'read', plist_file, 'HiddenUsersList' ]
|
||||||
(rc, out, err) = self.execute_command(cmd)
|
(rc, out, err) = self.execute_command(cmd)
|
||||||
# returned value is
|
# returned value is
|
||||||
|
@ -1590,6 +1608,8 @@ class DarwinUser(User):
|
||||||
|
|
||||||
|
|
||||||
self._make_group_numerical()
|
self._make_group_numerical()
|
||||||
|
if self.uid is None:
|
||||||
|
self.uid = str(self._get_next_uid())
|
||||||
|
|
||||||
# Homedir is not created by default
|
# Homedir is not created by default
|
||||||
if self.createhome:
|
if self.createhome:
|
||||||
|
@ -1651,7 +1671,7 @@ class DarwinUser(User):
|
||||||
changed = rc
|
changed = rc
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if self.update_password == 'always':
|
if self.update_password == 'always' and self.password is not None:
|
||||||
(rc, _err, _out) = self._change_user_password()
|
(rc, _err, _out) = self._change_user_password()
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue