Adds tmux to the ubuntu_lxc and ubuntu_vm profiles and an opt-in
/etc/profile.d snippet that attaches an interactive SSH login to a tmux
session, created with configurable windows when it does not exist.
- system_baseline_tmux_autostart (default false), _session (default main)
and _windows ([{name, command}]); only ubuntu_lxc and ubuntu_vm install
the snippet, pve never does, and false removes it.
- profile.d is read only by an interactive login shell, so scp, sftp,
ssh host command and automation are unaffected. ~/.no-tmux opts a user
out. ForceCommand is not used: it would affect every session type.
- Names and commands are validated and shell-quoted; the script is
root-owned. Commands run as the logging-in user and are world-readable,
so they must hold no secret.
- Molecule converge enables it, verify checks ownership, mode, the attach
line, the quoting and sh -n.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q72rsMEKREGMfB9DH3T9mR
105 lines
4.0 KiB
YAML
105 lines
4.0 KiB
YAML
---
|
|
- name: Refuse an unknown system_baseline_system_type
|
|
hosts: all
|
|
gather_facts: false
|
|
tasks:
|
|
- name: Run the role with a bad system_baseline_system_type
|
|
block:
|
|
- name: Include system_baseline
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
vars:
|
|
system_baseline_system_type: not_a_type
|
|
- name: Unreachable when validation works
|
|
ansible.builtin.fail:
|
|
msg: system_baseline ran with an invalid system_baseline_system_type
|
|
rescue:
|
|
- name: The validation stopped the play
|
|
ansible.builtin.assert:
|
|
that: "'is invalid' in ansible_failed_result.msg | default('')"
|
|
quiet: true
|
|
|
|
- name: Converge the LXC profile
|
|
hosts: all
|
|
gather_facts: true
|
|
vars:
|
|
system_baseline_system_type: ubuntu_lxc
|
|
system_baseline_tmux_autostart: true
|
|
system_baseline_tmux_session: molecule
|
|
system_baseline_tmux_windows:
|
|
- { name: logs, command: "echo 'a b'; true" }
|
|
roles:
|
|
- role: mortis.kamino.system_baseline
|
|
|
|
# The remaining plays only load the role's defaults (validate.yml changes nothing) and assert
|
|
# the resolved inputs. They cover the profiles the converge above cannot run.
|
|
- name: The pve profile resolves
|
|
hosts: all
|
|
gather_facts: false
|
|
vars:
|
|
system_baseline_system_type: pve
|
|
tasks:
|
|
- name: Load the role defaults
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: validate.yml
|
|
public: true
|
|
- name: Assert the pve profile
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "'ufw' not in system_baseline_essential_packages"
|
|
- "'tmux' not in system_baseline_essential_packages"
|
|
- not system_baseline_tmux_autostart
|
|
- "'unattended-upgrades' in system_baseline_essential_packages"
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == false
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '03:00'
|
|
- system_baseline_secure_tmp_mounts == ['/dev/shm', '/tmp', '/var/tmp']
|
|
quiet: true
|
|
|
|
- name: The ubuntu_vm profile resolves
|
|
hosts: all
|
|
gather_facts: false
|
|
vars:
|
|
system_baseline_system_type: ubuntu_vm
|
|
tasks:
|
|
- name: Load the role defaults
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: validate.yml
|
|
public: true
|
|
- name: Assert the ubuntu_vm profile
|
|
ansible.builtin.assert:
|
|
that:
|
|
- "'qemu-guest-agent' in system_baseline_essential_packages"
|
|
- "'tmux' in system_baseline_essential_packages"
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == false
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '04:00'
|
|
- system_baseline_sysctl_hardening | selectattr('name', 'equalto', 'net.ipv4.conf.all.log_martians') | list | length == 1
|
|
quiet: true
|
|
|
|
# Consumer play vars override the profile.
|
|
- name: Consumer overrides win over the profile
|
|
hosts: all
|
|
gather_facts: false
|
|
vars:
|
|
system_baseline_system_type: ubuntu_vm
|
|
system_baseline_remove_packages: [telnet]
|
|
system_baseline_profile_overrides:
|
|
ubuntu_vm:
|
|
unattended_upgrade_settings:
|
|
"Unattended-Upgrade::Automatic-Reboot": true
|
|
tasks:
|
|
- name: Load the role defaults
|
|
ansible.builtin.include_role:
|
|
name: mortis.kamino.system_baseline
|
|
tasks_from: validate.yml
|
|
public: true
|
|
- name: Assert the overrides
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_remove_packages == ['telnet']
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot'] == true
|
|
- system_baseline_unattended_upgrade_settings['Unattended-Upgrade::Automatic-Reboot-Time'] == '04:00'
|
|
- "'qemu-guest-agent' in system_baseline_essential_packages"
|
|
quiet: true
|