--- # The production profile: Ubuntu 24.04 LXCs. Only the profile name and the user are supplied. - name: Converge the role with a valid profile hosts: all vars: sshd_profile: ubuntu_lxc ansible_user: root roles: - role: mortis.kamino.sshd # The plays below only load the role's defaults and run validate.yml, which changes nothing # on the container. They cover the profiles the converge above cannot run and the values # the guards accept. - name: Every profile passes validation and keeps its root login policy hosts: all gather_facts: false tasks: - name: Validate each profile ansible.builtin.include_role: name: mortis.kamino.sshd tasks_from: validate.yml public: true vars: sshd_profile: "{{ item }}" loop: [pve, ubuntu_lxc, ubuntu_vm] - name: Assert the profile data ansible.builtin.assert: that: - sshd_profiles.pve.PermitRootLogin == "prohibit-password" - sshd_profiles.ubuntu_lxc.PermitRootLogin == "no" - sshd_profiles.ubuntu_vm.PermitRootLogin == "no" quiet: true # Proxmox cluster SSH needs RSA with SHA-2, never SHA-1 ssh-rsa; the others stay ed25519 only. - name: Assert the key algorithms per profile ansible.builtin.assert: that: - sshd_profiles.pve.HostKeyAlgorithms == "ssh-ed25519,rsa-sha2-512,rsa-sha2-256" - sshd_profiles.pve.PubkeyAcceptedAlgorithms == "ssh-ed25519,rsa-sha2-512,rsa-sha2-256" - sshd_settings_defaults.HostKeyAlgorithms == "ssh-ed25519" - sshd_settings_defaults.PubkeyAcceptedAlgorithms == "ssh-ed25519" - "'HostKeyAlgorithms' not in sshd_profiles.ubuntu_lxc" - "'HostKeyAlgorithms' not in sshd_profiles.ubuntu_vm" quiet: true # Play vars outrank the role defaults, so the override reaches the merged settings. - name: A consumer override wins and keeps the rest hosts: all gather_facts: false vars: sshd_profile: ubuntu_vm sshd_settings: MaxAuthTries: "5" tasks: - name: Load the role defaults ansible.builtin.include_role: name: mortis.kamino.sshd tasks_from: validate.yml public: true - name: Assert the override ansible.builtin.assert: that: - sshd_settings_effective.MaxAuthTries == "5" - sshd_settings_effective.PermitRootLogin == "no" - sshd_settings_effective.PubkeyAuthentication == "yes" quiet: true - name: The Proxmox guard accepts every value that allows root key login hosts: all gather_facts: false tasks: - name: Validate the pve profile with each accepted value ansible.builtin.include_role: name: mortis.kamino.sshd tasks_from: validate.yml vars: sshd_profile: pve sshd_settings: PermitRootLogin: "{{ item }}" loop: [prohibit-password, without-password, "yes", Prohibit-Password]