39 lines
804 B
Bash
Executable File
39 lines
804 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ "$#" -ne 3 ]; then
|
|
echo "Usage: $0 <localfile> <remotefile> <host_vars_dir>"
|
|
exit 1
|
|
fi
|
|
|
|
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"
|
|
|