AnsibleModule.run_command returns a tuple of return code, stdout and stderr. The module main function of the user module expects user.create_user to return a tuple of return code, stdout and stderr. Fix the locations where stdout and stderr got reversed. Co-authored-by: Ruediger Pluem <53253255+rpluem-vf@users.noreply.github.com>
This commit is contained in:
parent
d4b7b8bae7
commit
8471814f86
2 changed files with 28 additions and 22 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
bugfixes:
|
||||||
|
- >
|
||||||
|
user - AnsibleModule.run_command returns a tuple of return code, stdout
|
||||||
|
and stderr. The module main function of the user module expects
|
||||||
|
user.create_user to return a tuple of return code, stdout and stderr.
|
||||||
|
Fix the locations where stdout and stderr got reversed.
|
|
@ -674,9 +674,9 @@ class User(object):
|
||||||
cmd.append('-r')
|
cmd.append('-r')
|
||||||
|
|
||||||
cmd.append(self.name)
|
cmd.append(self.name)
|
||||||
(rc, err, out) = self.execute_command(cmd)
|
(rc, out, err) = self.execute_command(cmd)
|
||||||
if not self.local or rc != 0:
|
if not self.local or rc != 0:
|
||||||
return (rc, err, out)
|
return (rc, out, err)
|
||||||
|
|
||||||
if self.expires is not None:
|
if self.expires is not None:
|
||||||
if self.expires < time.gmtime(0):
|
if self.expires < time.gmtime(0):
|
||||||
|
@ -684,17 +684,17 @@ class User(object):
|
||||||
else:
|
else:
|
||||||
# Convert seconds since Epoch to days since Epoch
|
# Convert seconds since Epoch to days since Epoch
|
||||||
lexpires = int(math.floor(self.module.params['expires'])) // 86400
|
lexpires = int(math.floor(self.module.params['expires'])) // 86400
|
||||||
(rc, _err, _out) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name])
|
(rc, _out, _err) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name])
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
if self.groups is None or len(self.groups) == 0:
|
if self.groups is None or len(self.groups) == 0:
|
||||||
return (rc, err, out)
|
return (rc, out, err)
|
||||||
|
|
||||||
for add_group in groups:
|
for add_group in groups:
|
||||||
(rc, _err, _out) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group])
|
(rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group])
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
@ -848,35 +848,35 @@ class User(object):
|
||||||
cmd.append('-p')
|
cmd.append('-p')
|
||||||
cmd.append(self.password)
|
cmd.append(self.password)
|
||||||
|
|
||||||
(rc, err, out) = (None, '', '')
|
(rc, out, err) = (None, '', '')
|
||||||
|
|
||||||
# skip if no usermod changes to be made
|
# skip if no usermod changes to be made
|
||||||
if len(cmd) > 1:
|
if len(cmd) > 1:
|
||||||
cmd.append(self.name)
|
cmd.append(self.name)
|
||||||
(rc, err, out) = self.execute_command(cmd)
|
(rc, out, err) = self.execute_command(cmd)
|
||||||
|
|
||||||
if not self.local or not (rc is None or rc == 0):
|
if not self.local or not (rc is None or rc == 0):
|
||||||
return (rc, err, out)
|
return (rc, out, err)
|
||||||
|
|
||||||
if lexpires is not None:
|
if lexpires is not None:
|
||||||
(rc, _err, _out) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name])
|
(rc, _out, _err) = self.execute_command([lchage_cmd, '-E', to_native(lexpires), self.name])
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
if len(lgroupmod_add) == 0 and len(lgroupmod_del) == 0:
|
if len(lgroupmod_add) == 0 and len(lgroupmod_del) == 0:
|
||||||
return (rc, err, out)
|
return (rc, out, err)
|
||||||
|
|
||||||
for add_group in lgroupmod_add:
|
for add_group in lgroupmod_add:
|
||||||
(rc, _err, _out) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group])
|
(rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-M', self.name, add_group])
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
for del_group in lgroupmod_del:
|
for del_group in lgroupmod_del:
|
||||||
(rc, _err, _out) = self.execute_command([lgroupmod_cmd, '-m', self.name, del_group])
|
(rc, _out, _err) = self.execute_command([lgroupmod_cmd, '-m', self.name, del_group])
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
@ -2239,20 +2239,20 @@ class DarwinUser(User):
|
||||||
|
|
||||||
if self.append is False:
|
if self.append is False:
|
||||||
for remove in current - target:
|
for remove in current - target:
|
||||||
(_rc, _err, _out) = self.__modify_group(remove, 'delete')
|
(_rc, _out, _err) = self.__modify_group(remove, 'delete')
|
||||||
rc += rc
|
rc += rc
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
for add in target - current:
|
for add in target - current:
|
||||||
(_rc, _err, _out) = self.__modify_group(add, 'add')
|
(_rc, _out, _err) = self.__modify_group(add, 'add')
|
||||||
rc += _rc
|
rc += _rc
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
return (rc, err, out, changed)
|
return (rc, out, err, changed)
|
||||||
|
|
||||||
def _update_system_user(self):
|
def _update_system_user(self):
|
||||||
'''Hide or show user on login window according SELF.SYSTEM.
|
'''Hide or show user on login window according SELF.SYSTEM.
|
||||||
|
@ -2323,7 +2323,7 @@ class DarwinUser(User):
|
||||||
def create_user(self, command_name='dscl'):
|
def create_user(self, command_name='dscl'):
|
||||||
cmd = self._get_dscl()
|
cmd = self._get_dscl()
|
||||||
cmd += ['-create', '/Users/%s' % self.name]
|
cmd += ['-create', '/Users/%s' % self.name]
|
||||||
(rc, err, out) = self.execute_command(cmd)
|
(rc, out, err) = self.execute_command(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg='Cannot create user "%s".' % self.name, err=err, out=out, rc=rc)
|
self.module.fail_json(msg='Cannot create user "%s".' % self.name, err=err, out=out, rc=rc)
|
||||||
|
|
||||||
|
@ -2350,16 +2350,16 @@ class DarwinUser(User):
|
||||||
|
|
||||||
cmd = self._get_dscl()
|
cmd = self._get_dscl()
|
||||||
cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
|
cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
|
||||||
(rc, _err, _out) = self.execute_command(cmd)
|
(rc, _out, _err) = self.execute_command(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(msg='Cannot add property "%s" to user "%s".' % (field[0], self.name), err=err, out=out, rc=rc)
|
self.module.fail_json(msg='Cannot add property "%s" to user "%s".' % (field[0], self.name), err=err, out=out, rc=rc)
|
||||||
|
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
return (rc, _err, _out)
|
return (rc, _out, _err)
|
||||||
|
|
||||||
(rc, _err, _out) = self._change_user_password()
|
(rc, _out, _err) = self._change_user_password()
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
|
|
||||||
|
@ -2370,7 +2370,7 @@ class DarwinUser(User):
|
||||||
(rc, _out, _err, changed) = self._modify_group()
|
(rc, _out, _err, changed) = self._modify_group()
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
return (rc, err, out)
|
return (rc, out, err)
|
||||||
|
|
||||||
def modify_user(self):
|
def modify_user(self):
|
||||||
changed = None
|
changed = None
|
||||||
|
@ -2386,7 +2386,7 @@ class DarwinUser(User):
|
||||||
if current is None or current != to_text(self.__dict__[field[0]]):
|
if current is None or current != to_text(self.__dict__[field[0]]):
|
||||||
cmd = self._get_dscl()
|
cmd = self._get_dscl()
|
||||||
cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
|
cmd += ['-create', '/Users/%s' % self.name, field[1], self.__dict__[field[0]]]
|
||||||
(rc, _err, _out) = self.execute_command(cmd)
|
(rc, _out, _err) = self.execute_command(cmd)
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
self.module.fail_json(
|
self.module.fail_json(
|
||||||
msg='Cannot update property "%s" for user "%s".'
|
msg='Cannot update property "%s" for user "%s".'
|
||||||
|
@ -2395,7 +2395,7 @@ class DarwinUser(User):
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
if self.update_password == 'always' and self.password is not None:
|
if self.update_password == 'always' and self.password is not None:
|
||||||
(rc, _err, _out) = self._change_user_password()
|
(rc, _out, _err) = self._change_user_password()
|
||||||
out += _out
|
out += _out
|
||||||
err += _err
|
err += _err
|
||||||
changed = rc
|
changed = rc
|
||||||
|
|
Loading…
Reference in a new issue