--- - name: Fail if sshd_profile is not set ansible.builtin.fail: msg: "sshd_profile must be set (pve, ubuntu_lxc, ubuntu_vm)" when: sshd_profile is not defined - name: Fail if sshd_profile is unknown ansible.builtin.fail: msg: "sshd_profile '{{ sshd_profile }}' is invalid. Must be: {{ sshd_profiles.keys() | sort | join(', ') }}." when: sshd_profile not in sshd_profiles - name: Fail if no sshd settings are defined ansible.builtin.fail: msg: "No sshd settings resolved after merging defaults and overrides." when: sshd_settings_effective | length == 0 - name: Fail if SSH would be locked out ansible.builtin.fail: msg: > SSH hardening would lock you out. PasswordAuthentication is disabled and PubkeyAuthentication is not enabled. when: - sshd_settings_effective.PasswordAuthentication | default("yes") == "no" - sshd_settings_effective.PubkeyAuthentication | default("no") != "yes" - name: Fail if root key login is disabled on Proxmox ansible.builtin.fail: msg: > Proxmox cluster SSH needs root public-key login. PermitRootLogin must be prohibit-password, without-password or yes, not '{{ sshd_settings_effective.PermitRootLogin }}'. # forced-commands-only is refused too: the cluster's tunnels run arbitrary commands # with keys that carry no command= option. An unset value keeps the OpenSSH default, # prohibit-password. sshd matches the value case-insensitively, so the guard does too; # a YAML boolean (unquoted yes) becomes "true" and is refused, as sshd would refuse it. when: - sshd_profile == "pve" - >- sshd_settings_effective.PermitRootLogin | default("prohibit-password") | string | lower not in ["prohibit-password", "without-password", "yes"] - name: Fail if RSA keys are refused on Proxmox ansible.builtin.fail: msg: > Proxmox cluster SSH pins RSA host keys and logs in with root's RSA key. HostKeyAlgorithms and PubkeyAcceptedAlgorithms must both include rsa-sha2-512. # An unset directive keeps the OpenSSH default, which includes rsa-sha2-512. The # +/-/^ list forms are not parsed, so they fail here: write the full list. when: - sshd_profile == "pve" - >- 'rsa-sha2-512' not in (sshd_settings_effective.HostKeyAlgorithms | default('rsa-sha2-512') | split(',') | map('trim')) or 'rsa-sha2-512' not in (sshd_settings_effective.PubkeyAcceptedAlgorithms | default('rsa-sha2-512') | split(',') | map('trim')) - name: Fail if SHA-1 RSA (ssh-rsa) is allowed ansible.builtin.fail: msg: > HostKeyAlgorithms and PubkeyAcceptedAlgorithms must not list ssh-rsa (RSA with SHA-1); use rsa-sha2-512/rsa-sha2-256. when: >- 'ssh-rsa' in (sshd_settings_effective.HostKeyAlgorithms | default('') | split(',') | map('trim')) or 'ssh-rsa' in (sshd_settings_effective.PubkeyAcceptedAlgorithms | default('') | split(',') | map('trim'))