ansible-roles/evolinux-users/tasks/ssh_allowusers.yml
Patrick Marchand 9049a97792 Simplify evolinux-users ssh tasks
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.
2019-08-06 17:53:21 -04:00

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