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
43 lines
2.2 KiB
YAML
43 lines
2.2 KiB
YAML
---
|
|
# Attach an interactive SSH login to a tmux session, created with the configured windows when it does not exist.
|
|
# /etc/profile.d is read only by an interactive login shell, so scp, sftp, `ssh host command` and automation never trigger it.
|
|
# sshd's ForceCommand is deliberately not used: it applies to every session type and a broken tmux would lock out all of them.
|
|
#
|
|
# Security: the session name, window names and commands are role inputs (inventory), never read from a user or a fact. They are
|
|
# validated here and shell-quoted in the template. The script is root-owned and not writable by the users it runs for. It is
|
|
# world-readable and the commands show in `ps`, so a command must hold no secret. Commands run as the user who logs in.
|
|
- name: Check the tmux inputs
|
|
ansible.builtin.assert:
|
|
that:
|
|
- system_baseline_tmux_session is match('^[A-Za-z0-9_-]{1,32}$')
|
|
- system_baseline_tmux_windows is sequence and system_baseline_tmux_windows is not string
|
|
- system_baseline_tmux_windows | map(attribute='name', default='') | map('regex_search', '^[A-Za-z0-9_-]{1,32}$') | select | list | length
|
|
== system_baseline_tmux_windows | length
|
|
- system_baseline_tmux_windows | map(attribute='command', default='') | select('match', '^[^\n\r]+$') | list | length
|
|
== system_baseline_tmux_windows | length
|
|
fail_msg: >-
|
|
system_baseline_tmux_session must be 1-32 characters of A-Z a-z 0-9 _ - ; every system_baseline_tmux_windows entry needs
|
|
a name (same characters) and a one-line command.
|
|
quiet: true
|
|
when: system_baseline_tmux_autostart | bool
|
|
|
|
- name: Install the tmux auto-start snippet
|
|
ansible.builtin.template:
|
|
src: tmux-autostart.sh.j2
|
|
dest: /etc/profile.d/tmux-autostart.sh
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
validate: /bin/sh -n %s
|
|
when:
|
|
- system_baseline_tmux_autostart | bool
|
|
- system_baseline_system_type in ['ubuntu_lxc', 'ubuntu_vm']
|
|
become: true
|
|
|
|
- name: Remove the tmux auto-start snippet
|
|
ansible.builtin.file:
|
|
path: /etc/profile.d/tmux-autostart.sh
|
|
state: absent
|
|
when: not (system_baseline_tmux_autostart | bool and system_baseline_system_type in ['ubuntu_lxc', 'ubuntu_vm'])
|
|
become: true
|