evolinux-users: deal with AllowGroups and AllowUsers differently
This commit is contained in:
parent
6cb1a5765a
commit
c18b83d974
|
@ -26,15 +26,28 @@
|
|||
loop_var: ssk_key
|
||||
when: user.ssh_keys is defined
|
||||
|
||||
# we must double-escape caracters, because python
|
||||
- name: verify AllowUsers directive
|
||||
- name: verify AllowGroups directive
|
||||
shell: "grep -E '^AllowGroups' /etc/ssh/sshd_config"
|
||||
changed_when: False
|
||||
failed_when: False
|
||||
register: grep_allowgroups_ssh
|
||||
check_mode: no
|
||||
|
||||
# If AllowGroups is present, we don't change
|
||||
- debug:
|
||||
msg: "AllowGroups detected : You have to configure SSH manually"
|
||||
when: grep_allowgroups_ssh.rc == 0
|
||||
|
||||
- block:
|
||||
# If AllowGroups is not present, we proceed as usual
|
||||
- name: verify AllowUsers directive
|
||||
shell: "grep -E '^AllowUsers' /etc/ssh/sshd_config"
|
||||
changed_when: False
|
||||
failed_when: False
|
||||
register: grep_allowusers_ssh
|
||||
check_mode: no
|
||||
|
||||
- name: "Add AllowUsers sshd directive for '{{ user.name }}'"
|
||||
- name: "Add AllowUsers sshd directive for '{{ user.name }}'"
|
||||
lineinfile:
|
||||
dest: /etc/ssh/sshd_config
|
||||
line: "\nAllowUsers {{ user.name }}"
|
||||
|
@ -43,7 +56,7 @@
|
|||
notify: reload sshd
|
||||
when: grep_allowusers_ssh.rc != 0
|
||||
|
||||
- name: "Modify AllowUsers sshd directive for '{{ user.name }}'"
|
||||
- name: "Modify AllowUsers sshd directive for '{{ user.name }}'"
|
||||
replace:
|
||||
dest: /etc/ssh/sshd_config
|
||||
regexp: '^(AllowUsers ((?!\b{{ user.name }}\b).)*)$'
|
||||
|
@ -52,14 +65,14 @@
|
|||
notify: reload sshd
|
||||
when: grep_allowusers_ssh.rc == 0
|
||||
|
||||
- name: "verify Match User directive"
|
||||
- name: "verify Match User directive"
|
||||
command: "grep 'Match User' /etc/ssh/sshd_config"
|
||||
changed_when: False
|
||||
failed_when: False
|
||||
register: grep_matchuser_ssh
|
||||
check_mode: no
|
||||
|
||||
- name: "Add Match User sshd directive for '{{ user.name }}' (Jessie)"
|
||||
- name: "Add Match User sshd directive for '{{ user.name }}' (Jessie)"
|
||||
lineinfile:
|
||||
dest: /etc/ssh/sshd_config
|
||||
line: "\nMatch User {{ user.name }}\n PasswordAuthentication no"
|
||||
|
@ -70,7 +83,7 @@
|
|||
- ansible_distribution_release == "jessie"
|
||||
- grep_matchuser_ssh.rc != 0
|
||||
|
||||
- name: "Modify Match User's sshd directive for '{{ user.name }}' (Jessie)"
|
||||
- name: "Modify Match User's sshd directive for '{{ user.name }}' (Jessie)"
|
||||
replace:
|
||||
dest: /etc/ssh/sshd_config
|
||||
regexp: '^(Match User ((?!{{ user.name }}).)*)$'
|
||||
|
@ -80,3 +93,5 @@
|
|||
when:
|
||||
- ansible_distribution_release == "jessie"
|
||||
- grep_matchuser_ssh.rc == 0
|
||||
|
||||
when: grep_allowgroups_ssh.rc != 0
|
||||
|
|
Loading…
Reference in a new issue