Skip to content

Commit cc14a8b

Browse files
committed
test ssh socket and variants
Signed-off-by: Thomas Sjögren <[email protected]>
1 parent 74a9bba commit cc14a8b

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

handlers/main.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,34 @@
7878
when:
7979
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
8080

81-
- name: Restart ssh service
81+
- name: Restart ssh socket
8282
become: true
8383
ansible.builtin.service:
84-
name: ssh
84+
name: "{{ 'ssh.socket' if ansible_facts.os_family == 'Debian' else 'sshd.socket' }}"
8585
state: restarted
86-
register: ssh_service
87-
failed_when:
88-
- ssh_service is not success
89-
- not 'Could not find the requested service' in ssh_service.msg
86+
enabled: true
9087
when:
9188
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
89+
- ansible_facts.distribution == "Ubuntu"
9290

93-
- name: Restart sshd service
91+
- name: Restart ssh service
9492
become: true
9593
ansible.builtin.service:
96-
name: sshd
94+
name: "{{ 'ssh.service' if ansible_facts.os_family == 'Debian' else 'sshd.service' }}"
9795
state: restarted
98-
register: sshd_service
99-
failed_when:
100-
- sshd_service is not success
101-
- not 'Could not find the requested service' in sshd_service.msg
96+
enabled: true
97+
when:
98+
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
99+
100+
- name: Disable ssh service
101+
become: true
102+
ansible.builtin.service:
103+
name: "{{ 'ssh.service' if ansible_facts.os_family == 'Debian' else 'sshd.service' }}"
104+
state: stopped
105+
enabled: false
102106
when:
103107
- ansible_facts.virtualization_type not in ["container", "docker", "podman"]
108+
- ansible_facts.distribution == "Ubuntu"
104109

105110
- name: Restart Postfix
106111
become: true

tasks/sshconfig.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@
250250
(not sshd_config_d.stat.exists) or
251251
(grep_include.rc != 0)
252252
notify:
253-
- Restart sshd service
253+
- Disable ssh service
254+
- Restart ssh socket
254255
- Restart ssh service
255256

256257
- name: Configure sshd using sshd_config.d
@@ -268,7 +269,8 @@
268269
- sshd_config_d.stat.exists
269270
- grep_include.rc == 0
270271
notify:
271-
- Restart sshd service
272+
- Disable ssh service
273+
- Restart ssh socket
272274
- Restart ssh service
273275

274276
- name: Remove possible Subsystem duplicate

0 commit comments

Comments
 (0)