2018-03-01 11:07:43 +01:00
|
|
|
---
|
|
|
|
|
2024-05-07 15:11:09 +02:00
|
|
|
###
|
2018-03-01 18:26:18 +01:00
|
|
|
# this check must be repeated for each user
|
|
|
|
# even if it's been done before
|
2024-05-07 15:11:09 +02:00
|
|
|
|
|
|
|
- name: Fetch SSHd config files
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: "find /etc/ssh -type f \\( -name 'sshd_config' -o -path '/etc/ssh/sshd_config.d/*.conf' \\)"
|
|
|
|
changed_when: False
|
|
|
|
check_mode: no
|
|
|
|
register: _ssh_config_paths
|
|
|
|
|
2018-03-01 18:26:18 +01:00
|
|
|
- name: verify AllowGroups directive
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
2024-05-07 15:11:09 +02:00
|
|
|
cmd: "grep --extended-regexp --recursive --files-with-matches '^AllowGroups' {{ _ssh_config_paths.stdout_lines | join(' ') }}"
|
2018-03-01 18:26:18 +01:00
|
|
|
changed_when: False
|
|
|
|
failed_when: False
|
|
|
|
check_mode: no
|
|
|
|
register: grep_allowgroups_ssh
|
2018-03-01 11:07:43 +01:00
|
|
|
|
2024-05-07 15:11:09 +02:00
|
|
|
###
|
|
|
|
|
|
|
|
- name: "Add AllowGroups sshd directive with '{{ evolinux_ssh_group }}' (Debian < 12)"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2018-03-01 11:07:43 +01:00
|
|
|
dest: /etc/ssh/sshd_config
|
|
|
|
line: "\nAllowGroups {{ evolinux_ssh_group }}"
|
|
|
|
insertafter: 'Subsystem'
|
2019-06-17 10:23:56 +02:00
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
2018-03-01 11:07:43 +01:00
|
|
|
notify: reload sshd
|
2023-04-17 18:03:19 +02:00
|
|
|
when:
|
|
|
|
- ansible_distribution_major_version is version('11', '<=')
|
2024-05-07 15:11:09 +02:00
|
|
|
- grep_allowgroups_ssh.rc == 1 # Not found
|
|
|
|
|
|
|
|
- name: "Add AllowGroups sshd directive with '{{ evolinux_ssh_group }}' (Debian >= 12)"
|
|
|
|
ansible.builtin.lineinfile:
|
|
|
|
dest: /etc/ssh/sshd_config.d/z-evolinux-users.conf
|
|
|
|
line: "\nAllowGroups {{ evolinux_ssh_group }}"
|
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
|
|
create: yes
|
|
|
|
notify: reload sshd
|
|
|
|
when:
|
|
|
|
- ansible_distribution_major_version is version('12', '>=')
|
|
|
|
- grep_allowgroups_ssh.rc == 1 # Not found
|
2018-03-01 11:07:43 +01:00
|
|
|
|
|
|
|
- name: "Append '{{ evolinux_ssh_group }}' to AllowGroups sshd directive"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.replace:
|
2024-05-07 15:11:09 +02:00
|
|
|
dest: "{{ grep_allowgroups_ssh.stdout_lines[0] }}"
|
2018-03-01 11:07:43 +01:00
|
|
|
regexp: '^(AllowGroups ((?!\b{{ evolinux_ssh_group }}\b).)*)$'
|
2018-03-01 18:26:18 +01:00
|
|
|
replace: '\1 {{ evolinux_ssh_group }}'
|
2019-06-17 10:23:56 +02:00
|
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
2018-03-01 11:07:43 +01:00
|
|
|
notify: reload sshd
|
2023-04-17 18:03:19 +02:00
|
|
|
when:
|
2024-05-07 15:11:09 +02:00
|
|
|
- grep_allowgroups_ssh.rc == 0 or grep_allowgroups_ssh.rc == 2 # Found, return code can be 0 or 2
|