--- - name: Disable SSH passwords become: true lineinfile: path: /etc/ssh/sshd_config regexp: '^#?\w*PasswordAuthentication (yes|no)' line: 'PasswordAuthentication no' register: changed_ssh_config - name: Enable SSH (Linux) become: true systemd: name: ssh.service enabled: yes state: started when: ansible_system == 'Linux' - name: Enable SSH (FreeBSD) become: true service: name: sshd enabled: yes state: started when: ansible_system == 'FreeBSD' - name: Restart SSH (Linux) become: true systemd: name: ssh.service state: restarted when: changed_ssh_config.changed == true and ansible_system == 'Linux' - name: Restart SSH (FreeBSD) become: true service: name: sshd state: restarted when: changed_ssh_config.changed == true and ansible_system == 'FreeBSD'