4 {{ [ 'root' ] | union(user_groups.noc)
5 | union(sshd_allowusers_group | default([]))
6 | union(sshd_allowusers_host | default([])) }}
8 - name: only allow pubkey auth for root
10 dest: /etc/ssh/sshd_config
11 regexp: "^PermitRootLogin"
12 line: "PermitRootLogin without-password"
15 - name: limit allowed users (1/2)
16 when: sshd_allowgroup is not defined
18 dest: /etc/ssh/sshd_config
19 regexp: "^#?AllowUsers"
20 line: "AllowUsers {{ ' '.join(sshd_allowusers) }}"
24 - name: "limit allowed users (2/2): Make sure AllowUsers is not in sshd_config"
26 dest: /etc/ssh/sshd_config
31 - name: "limit allowed users (2/2): Set AllowGroups in sshd_config"
33 dest: /etc/ssh/sshd_config
34 regexp: "^#?AllowGroups"
35 line: AllowGroups {{ sshd_allowgroup }}
38 - name: "limit allowed users (2/2): Add allowed users to ssh group"
41 groups: "{{ sshd_allowgroup }}"
43 with_items: "{{ sshd_allowusers }}"
45 when: sshd_allowgroup is defined
47 - name: Set authorized keys for root user
50 key: "{{ ssh_users_root | user_ssh_keys(users) | join('\n') }}"