--- # 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