2 - name: generate list of users allowed to login via ssh
5 {{ [ 'root' ] | union(user_groups.noc)
6 | union(sshd_allowusers_group | default([]))
7 | union(sshd_allowusers_host | default([])) }}
9 - name: only allow pubkey auth for root
11 dest: /etc/ssh/sshd_config
12 regexp: "^PermitRootLogin"
13 line: "PermitRootLogin without-password"
16 - name: limit allowed users (1/2)
17 when: sshd_allowgroup is not defined
19 dest: /etc/ssh/sshd_config
20 regexp: "^#?AllowUsers"
21 line: "AllowUsers {{ ' '.join(sshd_allowusers) }}"
25 - name: "limit allowed users (2/2): Make sure AllowUsers is not in sshd_config"
27 dest: /etc/ssh/sshd_config
32 - name: "limit allowed users (2/2): Set AllowGroups in sshd_config"
34 dest: /etc/ssh/sshd_config
35 regexp: "^#?AllowGroups"
36 line: AllowGroups {{ sshd_allowgroup }}
39 - name: "limit allowed users (2/2): Add allowed users to ssh group"
42 groups: "{{ sshd_allowgroup }}"
44 with_items: "{{ sshd_allowusers }}"
46 when: sshd_allowgroup is defined
48 - name: Set authorized keys for root user
51 key: "{{ ssh_users_root | user_ssh_keys(users) | join('\n') }}"