diff --git a/alpine/rex b/alpine/rex index 92d575d..fd498dd 100755 --- a/alpine/rex +++ b/alpine/rex @@ -2,7 +2,12 @@ cmd="$*" -echo "Running on hosts: $cmd" +# Build a temporary hosts file without comments (# ...) and blank lines +tmp_hosts=$(mktemp) +trap 'rm -f "$tmp_hosts"' EXIT +sed -e 's/#.*$//' -e 's/[[:space:]]*$//' -e '/^[[:space:]]*$/d' /app/host_vars/hosts > "$tmp_hosts" -pssh -h /app/host_vars/hosts -t 0 "$cmd" +echo "Running on hosts: $(tr '\n' ' ' < "$tmp_hosts")" +echo "Command: $cmd" +pssh -h "$tmp_hosts" -t 0 "$cmd" diff --git a/alpine/template b/alpine/template index 3bdc469..96f29ac 100755 --- a/alpine/template +++ b/alpine/template @@ -21,7 +21,12 @@ case "$remotefile" in esac # Read hosts from file descriptor 3 to prevent ssh from consuming stdin -while read -r host <&3; do +while read -r host <&3 || [ -n "$host" ]; do + # Strip comments (# ...) and surrounding whitespace; skip empty lines + host="${host%%#*}" + host="${host//[[:space:]]/}" + [ -z "$host" ] && continue + host_env_file="$host_vars_dir/$host/$host.env" if [ ! -f "$host_env_file" ]; then diff --git a/app/vault/host_vars.img b/app/vault/host_vars.img index 08baff2..c1f9f19 100644 Binary files a/app/vault/host_vars.img and b/app/vault/host_vars.img differ