From 7a3e48aa825fcb5a7262ea5cc588b8a7268f1374 Mon Sep 17 00:00:00 2001 From: Riku Rouvila Date: Mon, 18 Dec 2023 15:24:09 +0200 Subject: [PATCH] change ssh restart method for ubuntu 23 --- infrastructure/server-setup/tasks/users.yml | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/infrastructure/server-setup/tasks/users.yml b/infrastructure/server-setup/tasks/users.yml index bc9b051f3..992dd0b26 100644 --- a/infrastructure/server-setup/tasks/users.yml +++ b/infrastructure/server-setup/tasks/users.yml @@ -156,9 +156,28 @@ register: check_result ignore_errors: yes -- name: Restart SSH service +# Ubuntu 22.10 +- name: Check if sshd service exists + command: systemctl status sshd + register: sshd_status + ignore_errors: yes + +- name: Restart SSH service (sshd) service: name: sshd state: restarted - when: check_result.rc == 0 + when: sshd_status.rc == 0 + become: yes + +# Ubuntu 23.10 +- name: Check if ssh service exists + command: systemctl status ssh + register: ssh_status + ignore_errors: yes + +- name: Restart SSH service (ssh) + service: + name: ssh + state: restarted + when: ssh_status.rc == 0 and sshd_status.rc != 0 become: yes