--- - debug: msg: "Warning: empty 'evolinux_ssh_password_auth_addresses' variable, tasks will be skipped!" when: evolinux_ssh_password_auth_addresses == [] - name: Security directives for Evolinux blockinfile: dest: /etc/ssh/sshd_config block: | Match Group evolix PasswordAuthentication no Match Address {{ evolinux_ssh_password_auth_addresses | join(',') }} PasswordAuthentication yes marker: "# {mark} EVOLINUX PASSWORD RESTRICTIONS" insertafter: EOF validate: '/usr/sbin/sshd -T -f %s' notify: reload sshd when: evolinux_ssh_password_auth_addresses != [] # We disable AcceptEnv because it can be a security issue, but also because we # do not want clients to push their environment variables like LANG. - name: disable AcceptEnv in ssh config replace: dest: /etc/ssh/sshd_config regexp: '^AcceptEnv' replace: "#AcceptEnv" notify: reload sshd when: evolinux_ssh_disable_acceptenv - name: Set log level to verbose (for Debian >= 9) replace: dest: /etc/ssh/sshd_config regexp: '^#?LogLevel [A-Z]+' replace: "LogLevel VERBOSE" notify: reload sshd when: ansible_distribution_major_version | version_compare('9', '>=') - name: "Get current user" command: logname register: logname check_mode: no changed_when: False when: evolinux_ssh_allow_current_user # we must double-escape caracters, because python - 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 when: evolinux_ssh_allow_current_user - name: "Add AllowUsers sshd directive for current user" lineinfile: dest: /etc/ssh/sshd_config line: "\nAllowUsers {{ logname.stdout }}" insertafter: 'Subsystem' validate: '/usr/sbin/sshd -T -f %s' notify: reload sshd when: evolinux_ssh_allow_current_user and grep_allowusers_ssh.rc != 0 - name: "Modify AllowUsers sshd directive for current user" replace: dest: /etc/ssh/sshd_config regexp: '^(AllowUsers ((?!{{ logname.stdout }}).)*)$' replace: '\1 {{ logname.stdout }}' validate: '/usr/sbin/sshd -T -f %s' notify: reload sshd when: evolinux_ssh_allow_current_user and grep_allowusers_ssh.rc == 0 - meta: flush_handlers