Skip to content

Commit

Permalink
Don't crash when removing basic_users (#361)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjpb authored Feb 20, 2024
1 parent e0c0932 commit 4801c83
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions ansible/roles/basic_users/library/terminate_user_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ def run_module():

_, sessions_stdout, _ = module.run_command("loginctl --no-legend list-sessions", check_rc=True)
for line in sessions_stdout.splitlines():
try:
session, uid, user = line.split()
except ValueError:
raise ValueError('failed to split "%s"' % line)

session_info = line.split()
user = session_info[1]
session_id = session_info[0]
if user == module.params['user']:
_, sessions_stdout, _ = module.run_command("loginctl terminate-session %s" % session, check_rc=True)
_, sessions_stdout, _ = module.run_command("loginctl terminate-session %s" % session_id, check_rc=True)
result['changed'] = True

# successful module exit:
Expand Down

0 comments on commit 4801c83

Please sign in to comment.