Refactor to reduce config in group_vars
This commit is contained in:
@@ -1,10 +1,30 @@
|
||||
---
|
||||
- name: Glob all files in role directory
|
||||
ansible.builtin.find:
|
||||
paths: "{{ role_path }}"
|
||||
depth: 1
|
||||
file_type: file
|
||||
register: scripts_files
|
||||
|
||||
- name: Deploy scripts to user's local bin
|
||||
ansible.builtin.include_tasks: ../../deploy_files.yml
|
||||
vars:
|
||||
var_prefix: scripts
|
||||
subdir: ''
|
||||
target_root: "{{ ansible_facts.env.HOME }}/.local/bin"
|
||||
use_symlinks: true
|
||||
become_root: false
|
||||
- name: "Ensure script directory exist"
|
||||
ansible.builtin.file:
|
||||
path: "{{ ansible_facts.env.HOME }}/.local/bin"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
|
||||
- name: "Deploy scripts (local with symlinks)"
|
||||
ansible.builtin.file:
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ ansible_facts.env.HOME }}/.local/bin/{{ item.path | basename }}"
|
||||
state: link
|
||||
force: true
|
||||
loop: "{{ scripts_files.files }}"
|
||||
when: ansible_connection in ['local', 'localhost']
|
||||
|
||||
- name: "Deploy scripts (remote with copy)"
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.path }}"
|
||||
dest: "{{ ansible_facts.env.HOME }}/.local/bin/{{ item.path | basename }}"
|
||||
mode: '0755'
|
||||
loop: "{{ scripts_files.files }}"
|
||||
when: ansible_connection not in ['local', 'localhost']
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
# Open a tiled tmux window with one pane per host each in its own tmux session.
|
||||
# The local session is always the last (active) pane.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Accept hostnames from command-line arguments
|
||||
if (( $# > 0 )); then
|
||||
HOSTS=("$@")
|
||||
else
|
||||
# Default hostnames in the desired pane order
|
||||
HOSTS=(
|
||||
workstation
|
||||
laptop
|
||||
)
|
||||
fi
|
||||
|
||||
# Configuration (override with env vars if desired)
|
||||
HOSTS=(workstation laptop) # hosts in pane order
|
||||
REMOTE_SESSION=${REMOTE_SESSION:-main} # tmux session on remotes
|
||||
SYNCHRONIZE=${SYNCHRONIZE:-1} # 1 = broadcast keystrokes
|
||||
INCLUDE_LOCAL=${INCLUDE_LOCAL:-1} # 0 = skip local host
|
||||
@@ -56,7 +65,8 @@ open_cmd() {
|
||||
printf 'tmux -L %q new -A -s %q' "${SESSION}_local" "$REMOTE_SESSION"
|
||||
fi
|
||||
else
|
||||
printf 'ssh -t %q tmux new -A -s %q' "$tgt" "$REMOTE_SESSION"
|
||||
# SSH with keepalive settings for faster broken pipe detection
|
||||
printf 'ssh -o ServerAliveInterval=20 -o ServerAliveCountMax=3 -t %q tmux new -A -s %q' "$tgt" "$REMOTE_SESSION"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -74,8 +84,8 @@ tmux select-layout -t "$SESSION:0" tiled
|
||||
# Keep panes visible when commands exit
|
||||
tmux set-option -t "$SESSION:0" remain-on-exit on
|
||||
|
||||
# Auto-respawn any pane whose command dies
|
||||
tmux set-hook -t "$SESSION" pane-died "run-shell 'tmux respawn-pane -k -t #{pane_id}'"
|
||||
# Reconnect dead panes when user focuses on them
|
||||
tmux set-hook -t "$SESSION" pane-focus-in "if -F '#{pane_dead}' 'respawn-pane -k -t #{pane_id}'"
|
||||
|
||||
# Activate the last pane (local host)
|
||||
local_index=$(( ${#TARGETS[@]} - 1 ))
|
||||
|
||||
Reference in New Issue
Block a user