mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
user: make system=yes work on Darwin systems. (#19464)
* Update system/user.py module. Add ability to add real system users with next free system uid (< 500) on macOS. * Improve syntax in system/user.py module. Remove complex if else line and replace by simple comparison which yields the same boolean value. * Remove "True" comparison of user.py. Remove comparison to true, as it is not pep8 conform.
This commit is contained in:
parent
71685b3258
commit
507b96ff30
1 changed files with 16 additions and 5 deletions
|
@ -1537,8 +1537,11 @@ class DarwinUser(User):
|
|||
else:
|
||||
return None
|
||||
|
||||
def _get_next_uid(self):
|
||||
'''Return the next available uid'''
|
||||
def _get_next_uid(self, system=None):
|
||||
'''
|
||||
Return the next available uid. If system=True, then
|
||||
uid should be below of 500, if possible.
|
||||
'''
|
||||
cmd = self._get_dscl()
|
||||
cmd += ['-list', '/Users', 'UniqueID']
|
||||
(rc, out, err) = self.execute_command(cmd, obey_checkmode=False)
|
||||
|
@ -1549,10 +1552,18 @@ class DarwinUser(User):
|
|||
out=out,
|
||||
err=err
|
||||
)
|
||||
|
||||
max_uid = 0
|
||||
max_system_uid = 0
|
||||
for line in out.splitlines():
|
||||
if max_uid < int(line.split()[1]):
|
||||
max_uid = int(line.split()[1])
|
||||
current_uid = int(line.split(' ')[-1])
|
||||
if max_uid < current_uid:
|
||||
max_uid = current_uid
|
||||
if max_system_uid < current_uid and current_uid < 500:
|
||||
max_system_uid = current_uid
|
||||
|
||||
if system and (0 < max_system_uid < 499):
|
||||
return max_system_uid + 1
|
||||
return max_uid + 1
|
||||
|
||||
def _change_user_password(self):
|
||||
|
@ -1711,7 +1722,7 @@ class DarwinUser(User):
|
|||
|
||||
self._make_group_numerical()
|
||||
if self.uid is None:
|
||||
self.uid = str(self._get_next_uid())
|
||||
self.uid = str(self._get_next_uid(self.system))
|
||||
|
||||
# Homedir is not created by default
|
||||
if self.createhome:
|
||||
|
|
Loading…
Reference in a new issue