merge
This commit is contained in:
39
alpine/template
Executable file
39
alpine/template
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$#" -ne 3 ]; then
|
||||
echo "Usage: $0 <localfile> <remotefile> <host_vars_dir>"
|
||||
exit 1
|
||||
fi
|
||||
hosts_file="/mnt/encrypted_volume/${HOSTS_FILE:-hosts.txt}"
|
||||
|
||||
localfile="$1"
|
||||
remotefile="$2"
|
||||
host_vars_dir="$3"
|
||||
|
||||
while read -r host; do
|
||||
echo "Processing host: $host"
|
||||
|
||||
host_env_file="$host_vars_dir/$host"
|
||||
|
||||
if [ ! -f "$host_env_file" ]; then
|
||||
echo "Warning: env file for host '$host' not found at $host_env_file. Skipping."
|
||||
continue
|
||||
fi
|
||||
|
||||
declare -A vars=()
|
||||
while IFS='=' read -r key value; do
|
||||
[[ -z "$key" || -z "$value" ]] && continue
|
||||
vars["$key"]="$value"
|
||||
done < "$host_env_file"
|
||||
|
||||
content=$(cat "$localfile")
|
||||
|
||||
for key in "${!vars[@]}"; do
|
||||
content=$(echo "$content" | sed "s|{$key}|${vars[$key]}|g")
|
||||
done
|
||||
|
||||
echo "Copying to $host:$remotefile"
|
||||
echo "$content" | ssh "$host" "cat > $remotefile"
|
||||
|
||||
done < "$hosts_file"
|
||||
|
||||
Reference in New Issue
Block a user