From 6431483d6f1642e57c1e3d00ade5cf72910b7894 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 22 Sep 2023 10:07:20 +0200 Subject: sshd: move service restart to handlers --- roles/sshd/handlers/main.yml | 6 ++++++ roles/sshd/tasks/main.yml | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 roles/sshd/handlers/main.yml (limited to 'roles/sshd') diff --git a/roles/sshd/handlers/main.yml b/roles/sshd/handlers/main.yml new file mode 100644 index 0000000..09355a9 --- /dev/null +++ b/roles/sshd/handlers/main.yml @@ -0,0 +1,6 @@ +- name: Restart sshd + become: true + ansible.builtin.systemd_service: + name: sshd + state: restarted + listen: sshd_restart diff --git a/roles/sshd/tasks/main.yml b/roles/sshd/tasks/main.yml index fb8d7cc..46eb0e1 100644 --- a/roles/sshd/tasks/main.yml +++ b/roles/sshd/tasks/main.yml @@ -7,11 +7,7 @@ group: root mode: '644' validate: /usr/sbin/sshd -t -f %s - register: sshd_config + notify: sshd_restart -- name: Restart sshd - become: true - ansible.builtin.systemd_service: - name: sshd - state: restarted - when: sshd_config.changed +- name: Restart sshd service if necessary + ansible.builtin.meta: flush_handlers -- cgit v1.2.3