Use AllowGroups mode also if no AllowUsers is present at all

This commit is contained in:
Jérémy Lecour 2018-03-01 15:57:17 +01:00 committed by Jérémy Lecour
parent 4fc58e4b1e
commit e0ac7760f0
3 changed files with 17 additions and 16 deletions

View file

@ -32,9 +32,17 @@
check_mode: no check_mode: no
register: grep_allowgroups_ssh register: grep_allowgroups_ssh
# If AllowGroups is present or Debian 9+, use AllowGroups mode - name: verify AllowUsers directive
shell: "grep -E '^AllowUsers' /etc/ssh/sshd_config"
changed_when: False
failed_when: False
check_mode: no
register: grep_allowusers_ssh
# If AllowGroups is present or
# if AllowUsers is absent and Debian 9+, use AllowGroups mode
- include: ssh_allowgroups.yml - include: ssh_allowgroups.yml
when: grep_allowgroups_ssh.rc == 0 or ansible_distribution_major_version | version_compare('9', '>=') when: grep_allowgroups_ssh.rc == 0 or (grep_allowusers_ssh.rc != 0 and ansible_distribution_major_version | version_compare('9', '>='))
# If AllowGroups is absent, use AllowUsers mode # If AllowGroups is absent, use AllowUsers mode
- include: ssh_allowusers.yml - include: ssh_allowusers.yml

View file

@ -29,13 +29,13 @@
notify: reload sshd notify: reload sshd
when: grep_allowgroups_ssh.rc == 0 when: grep_allowgroups_ssh.rc == 0
- name: disable AllowUsers directive if present # - name: disable AllowUsers directive if present
replace: # replace:
dest: /etc/ssh/sshd_config # dest: /etc/ssh/sshd_config
regexp: '^(AllowUsers)' # regexp: '^(AllowUsers)'
replace: '# \1' # replace: '# \1'
validate: '/usr/sbin/sshd -T -f %s' # validate: '/usr/sbin/sshd -T -f %s'
notify: reload sshd # notify: reload sshd
- name: "verify Match Group directive" - name: "verify Match Group directive"
command: "grep 'Match Group' /etc/ssh/sshd_config" command: "grep 'Match Group' /etc/ssh/sshd_config"

View file

@ -1,12 +1,5 @@
--- ---
- name: verify AllowUsers directive
shell: "grep -E '^AllowUsers' /etc/ssh/sshd_config"
changed_when: False
failed_when: False
check_mode: no
register: grep_allowusers_ssh
- name: "Add AllowUsers sshd directive with '{{ user.name }}'" - name: "Add AllowUsers sshd directive with '{{ user.name }}'"
lineinfile: lineinfile:
dest: /etc/ssh/sshd_config dest: /etc/ssh/sshd_config