Skip to content

Commit 4801c83

Browse files
authored
Don't crash when removing basic_users (#361)
1 parent e0c0932 commit 4801c83

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

ansible/roles/basic_users/library/terminate_user_sessions.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ def run_module():
5656

5757
_, sessions_stdout, _ = module.run_command("loginctl --no-legend list-sessions", check_rc=True)
5858
for line in sessions_stdout.splitlines():
59-
try:
60-
session, uid, user = line.split()
61-
except ValueError:
62-
raise ValueError('failed to split "%s"' % line)
63-
59+
session_info = line.split()
60+
user = session_info[1]
61+
session_id = session_info[0]
6462
if user == module.params['user']:
65-
_, sessions_stdout, _ = module.run_command("loginctl terminate-session %s" % session, check_rc=True)
63+
_, sessions_stdout, _ = module.run_command("loginctl terminate-session %s" % session_id, check_rc=True)
6664
result['changed'] = True
6765

6866
# successful module exit:

0 commit comments

Comments
 (0)