ssh: Ensure ssh enabled, use ssh.service unit on debian

This commit is contained in:
uumas
2026-08-02 00:10:15 +03:00
parent a1e6c03827
commit 1afc3338b1
3 changed files with 10 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
--- ---
- name: Restart sshd - name: Restart ssh service
ansible.builtin.systemd_service: ansible.builtin.systemd_service:
name: sshd.service name: "{{ _ssh_service_name }}"
state: restarted state: restarted

View File

@@ -6,8 +6,13 @@
line: "{{ item.key }} {{ item.value }}" line: "{{ item.key }} {{ item.value }}"
state: present state: present
validate: '/usr/sbin/sshd -t -f %s' validate: '/usr/sbin/sshd -t -f %s'
notify: Restart sshd notify: Restart ssh service
with_dict: with_dict:
PermitRootLogin: "prohibit-password" PermitRootLogin: "prohibit-password"
PasswordAuthentication: "{{ 'yes' if ssh_password_auth else 'no' }}" PasswordAuthentication: "{{ 'yes' if ssh_password_auth else 'no' }}"
X11Forwarding: "no" X11Forwarding: "no"
- name: Ensure ssh service is enabled
ansible.builtin.systemd_service:
name: "{{ _ssh_service_name }}"
enabled: true

2
roles/ssh/vars/main.yaml Normal file
View File

@@ -0,0 +1,2 @@
---
_ssh_service_name: "{{ 'ssh.service' if ansible_facts.os_family == 'Debian' else 'sshd.service' }}"