2018-03-01 11:07:43 +01:00
|
|
|
---
|
|
|
|
|
2018-03-01 18:26:18 +01:00
|
|
|
# this check must be repeated for each user
|
|
|
|
# even if it's been done before
|
|
|
|
- name: verify AllowGroups directive
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: "grep -E '^AllowGroups' /etc/ssh/sshd_config"
|
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
|
|
|
|
|
|
|
- name: "Add AllowGroups sshd directive with '{{ evolinux_ssh_group }}'"
|
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
|
|
|
|
when: grep_allowgroups_ssh.rc != 0
|
|
|
|
|
|
|
|
- name: "Append '{{ evolinux_ssh_group }}' to AllowGroups sshd directive"
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.replace:
|
2018-03-01 11:07:43 +01:00
|
|
|
dest: /etc/ssh/sshd_config
|
|
|
|
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
|
|
|
|
when: grep_allowgroups_ssh.rc == 0
|