- name: Disable PasswordAuthentication tags: - ssh block: - name: Disable PasswordAuthentication in sshd config ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: "^[#]?\\s?PasswordAuthentication" line: "PasswordAuthentication no" register: disable_passwds - name: Restart service sshd when: disable_passwds.changed ansible.builtin.service: name: sshd state: restarted