Fix the reversed order of return values (#72088)

* Fix the reversed order of return values

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.

* Fix another missed occurance

* Add changelog

* Fix further reversed order of return values occurrences

Followup to 72c3ba62c8:
Fix further reversed order of return values occurrences.
This commit is contained in:
Ruediger Pluem 2020-10-22 20:02:53 +02:00 committed by GitHub
parent c20329a0f6
commit e64ba97e8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 22 deletions

View file

@ -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.

View file

@ -675,9 +675,9 @@ class User(object):
cmd.append('-r')
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:
return (rc, err, out)
return (rc, out, err)
if self.expires is not None:
if self.expires < time.gmtime(0):
@ -685,17 +685,17 @@ class User(object):
else:
# Convert seconds since Epoch to days since Epoch
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
err += _err
if rc != 0:
return (rc, out, err)
if self.groups is None or len(self.groups) == 0:
return (rc, err, out)
return (rc, out, err)
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
err += _err
if rc != 0:
@ -849,35 +849,35 @@ class User(object):
cmd.append('-p')
cmd.append(self.password)
(rc, err, out) = (None, '', '')
(rc, out, err) = (None, '', '')
# skip if no usermod changes to be made
if len(cmd) > 1:
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):
return (rc, err, out)
return (rc, out, err)
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
err += _err
if rc != 0:
return (rc, out, err)
if len(lgroupmod_add) == 0 and len(lgroupmod_del) == 0:
return (rc, err, out)
return (rc, out, err)
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
err += _err
if rc != 0:
return (rc, out, err)
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
err += _err
if rc != 0:
@ -2240,20 +2240,20 @@ class DarwinUser(User):
if self.append is False:
for remove in current - target:
(_rc, _err, _out) = self.__modify_group(remove, 'delete')
(_rc, _out, _err) = self.__modify_group(remove, 'delete')
rc += rc
out += _out
err += _err
changed = True
for add in target - current:
(_rc, _err, _out) = self.__modify_group(add, 'add')
(_rc, _out, _err) = self.__modify_group(add, 'add')
rc += _rc
out += _out
err += _err
changed = True
return (rc, err, out, changed)
return (rc, out, err, changed)
def _update_system_user(self):
'''Hide or show user on login window according SELF.SYSTEM.
@ -2324,7 +2324,7 @@ class DarwinUser(User):
def create_user(self, command_name='dscl'):
cmd = self._get_dscl()
cmd += ['-create', '/Users/%s' % self.name]
(rc, err, out) = self.execute_command(cmd)
(rc, out, err) = self.execute_command(cmd)
if rc != 0:
self.module.fail_json(msg='Cannot create user "%s".' % self.name, err=err, out=out, rc=rc)
@ -2351,16 +2351,16 @@ class DarwinUser(User):
cmd = self._get_dscl()
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:
self.module.fail_json(msg='Cannot add property "%s" to user "%s".' % (field[0], self.name), err=err, out=out, rc=rc)
out += _out
err += _err
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
err += _err
@ -2371,7 +2371,7 @@ class DarwinUser(User):
(rc, _out, _err, changed) = self._modify_group()
out += _out
err += _err
return (rc, err, out)
return (rc, out, err)
def modify_user(self):
changed = None
@ -2387,7 +2387,7 @@ class DarwinUser(User):
if current is None or current != to_text(self.__dict__[field[0]]):
cmd = self._get_dscl()
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:
self.module.fail_json(
msg='Cannot update property "%s" for user "%s".'
@ -2396,7 +2396,7 @@ class DarwinUser(User):
out += _out
err += _err
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
err += _err
changed = rc