Patrick Marchand
9049a97792
It makes no sense to make a check before you include the task and do lt again after. Just use the pre-registered variables. This removes two tasks per user loop and one overall task.
38 lines
1.2 KiB
YAML
38 lines
1.2 KiB
YAML
---
|
|
|
|
- name: "Add AllowUsers sshd directive with '{{ user.name }}'"
|
|
lineinfile:
|
|
dest: /etc/ssh/sshd_config
|
|
line: "\nAllowUsers {{ user.name }}"
|
|
insertafter: 'Subsystem'
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
notify: reload sshd
|
|
when: not allow_users_present
|
|
|
|
- name: "Append '{{ user.name }}' to AllowUsers sshd directive"
|
|
replace:
|
|
dest: /etc/ssh/sshd_config
|
|
regexp: '^(AllowUsers ((?!\b{{ user.name }}\b).)*)$'
|
|
replace: '\1 {{ user.name }}'
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
notify: reload sshd
|
|
when: allow_users_present
|
|
|
|
- name: "Add Match User sshd directive with '{{ user.name }}'"
|
|
lineinfile:
|
|
dest: /etc/ssh/sshd_config
|
|
line: "\nMatch User {{ user.name }}\n PasswordAuthentication no"
|
|
insertafter: "# END EVOLINUX PASSWORD RESTRICTIONS BY ADDRESS"
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
notify: reload sshd
|
|
when: not allow_users_present
|
|
|
|
- name: "Append '{{ user.name }}' to Match User's sshd directive"
|
|
replace:
|
|
dest: /etc/ssh/sshd_config
|
|
regexp: '^(Match User ((?!{{ user.name }}).)*)$'
|
|
replace: '\1,{{ user.name }}'
|
|
validate: '/usr/sbin/sshd -t -f %s'
|
|
notify: reload sshd
|
|
when: match_users_present
|