diff --git a/salt/modules/pdbedit.py b/salt/modules/pdbedit.py index 210d02cb20..b25d79e0e1 100644 --- a/salt/modules/pdbedit.py +++ b/salt/modules/pdbedit.py @@ -92,29 +92,34 @@ def list_users(verbose=True, hashes=False): if res['retcode'] > 0: log.error(res['stderr'] if 'stderr' in res else res['stdout']) - else: - user_data = {} - for user in res['stdout'].splitlines(): - if user.startswith('-'): - if len(user_data) > 0: - users[user_data['unix username']] = user_data - user_data = {} - else: - label = user[:user.index(':')].strip().lower() - data = user[(user.index(':')+1):].strip() - user_data[label] = data + return users - if len(user_data) > 0: - users[user_data['unix username']] = user_data + user_data = {} + for user in res['stdout'].splitlines(): + if user.startswith('-'): + if 'unix username' in user_data: + users[user_data['unix username']] = user_data + user_data = {} + elif ':' in user: + label = user[:user.index(':')].strip().lower() + data = user[(user.index(':')+1):].strip() + user_data[label] = data + + if user_data: + users[user_data['unix username']] = user_data else: # list users res = __salt__['cmd.run_all']('pdbedit --list') if res['retcode'] > 0: return {'Error': res['stderr'] if 'stderr' in res else res['stdout']} - else: - for user in res['stdout'].splitlines(): - users.append(user.split(':')[0]) + + for user in res['stdout'].splitlines(): + if ':' not in user: + continue + user_data = user.split(':') + if len(user_data) >= 3: + users.append(user_data[0]) return users