molecule's trailing destroy runs the Docker driver's destroy playbook, whose "Wait for instance(s) deletion to complete" task alone costs about 5.6 s per scenario, about 84 s over the 15 scenarios of a full run. The whole destroy phase measured about 103 s per full run (the median across full runs, among them 4764, 4714, 4698 and 4578). The workflow already removes stale containers before the run, so it can remove each scenario's containers itself with `docker rm -f` as soon as the scenario ends, pass or fail, and skip the playbook. The names come from each scenario's molecule.yml (platforms[].name) via the molecule venv's Python and PyYAML, so no list is kept in the workflow. A failed removal fails the step. The test_sequence rule in the workflow guidance now says both destroys are left out and that platform names are literal. Assisted-by: Claude Code:claude-opus-5-5
sshd
Writes a hardened sshd drop-in, selected by a profile, and refuses configurations that would lock out SSH.
Supported platforms
Ubuntu 24.04 (noble), the image the molecule scenario runs on. 22.04 (jammy) and Debian trixie (Proxmox VE 9 nodes, the pve profile) are listed in meta/main.yml but not converged by a test; the pve drop-in is parsed by sshd -T in the scenario. The role uses ansible.builtin modules only.
Requirements and run order
- Use it by its fully qualified name,
mortis.kamino.sshd. - The target must be reachable over SSH and have
ssh-keygenandsshdinstalled. The role usesbecome. - Install the public key of
ansible_userbefore this role runs (for example with a user-management role earlier in the play), so key login works before password authentication is turned off. The role does not install keys. sshd_profileis set by the calling play:pve,ubuntu_lxcorubuntu_vm.- The role reads
ansible_userand setsansible_ssh_userto it for the rest of the play, in case the connection was bootstrapped as root. - Role dependencies are not declared in
meta/main.yml; the order above is the contract.
Role variables
meta/argument_specs.yml is the source of truth for types and descriptions.
| Name | Default | Required | Description |
|---|---|---|---|
sshd_profile |
none | yes | Profile key in sshd_profiles |
sshd_service_name |
sshd |
no | Service the handler reloads |
sshd_config_dir |
/etc/ssh/sshd_config.d |
no | Drop-in directory |
sshd_dropin_file |
99-ansible-hardening.conf |
no | Drop-in file name |
sshd_settings_defaults |
see defaults/main.yml |
no | Baseline directives for all profiles |
sshd_profiles |
see defaults/main.yml |
no | Per-profile directives; overriding replaces all profiles |
sshd_settings |
{} |
no | Directives merged over the profile key by key |
sshd_settings_effective |
derived | no | Merged result; read-only by convention. Not in spec |
sshd_reload |
true |
no | Reload sshd when the drop-in changes |
The drop-in contains sshd_settings_defaults, then the profile, then sshd_settings, later values winning.
sshd_settings_effective is deliberately not in the argument spec: its default indexes sshd_profiles[sshd_profile], and the spec is templated before tasks/validate.yml runs, so an unknown sshd_profile would fail at role entry with a templating error instead of the validation message.
Tags
The role defines none.
Example play
- name: Harden SSH on Ubuntu containers
hosts: containers
roles:
- role: mortis.kamino.sshd
vars:
sshd_profile: ubuntu_lxc
sshd_settings:
MaxAuthTries: "5"
Notes
tasks/validate.ymlfails the play for an unknown profile, an empty merged result,PasswordAuthentication nowithoutPubkeyAuthentication yes, apveprofile whosePermitRootLogindoes not allow root key login (prohibit-password, its aliaswithout-password, oryes;noandforced-commands-onlyare refused), apveprofile whoseHostKeyAlgorithmsorPubkeyAcceptedAlgorithmslacksrsa-sha2-512(the+/-/^list forms are not parsed and fail; write the full list), and any profile that lists SHA-1ssh-rsain either.- The drop-in is installed with
validate: sshd -t -f %s. The handler namedRestart SSHreloads the service, and is skipped in check mode or whensshd_reloadis false. ssh-keygen -Aruns on every play and always reports ok.meta/argument_specs.ymlhas only themainentry point.tasks_from: validate.ymlis used by the molecule scenario to load defaults and exercise the guards, not by consumers, so it has no spec.- The
pveprofile setsPermitRootLogin prohibit-password. Proxmox cluster SSH (migration, console proxy, replication) logs in as root with keys only. Passwords are already off throughPasswordAuthentication no; this keeps root key-only if they are ever turned back on. Join nodes through the default API join, notpvecm add --use_ssh, which needs root password SSH. - Host key and public key algorithms are
ssh-ed25519only, except in thepveprofile, which allowsssh-ed25519,rsa-sha2-512,rsa-sha2-256for both: Proxmox cluster SSH (migration, console proxy) checks each node's RSA host key against/etc/pve/nodes/<node>/ssh_known_hostsand logs in with root's RSA key. SHA-1ssh-rsastays refused. - Molecule:
molecule/default, run by the Collection's CI. It converges theubuntu_lxcprofile; thepveprofile is checked by rendering its drop-in to a scratch file and parsing it withsshd -T -f.