filter hosts
This commit is contained in:
1 parent
ac65ba2169
commit
9abed9f2e9
3 files changed
+13
-3
No files matched your search
+7
-2
@@ -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"
|
||||
+6
-1
@@ -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
|
||||
|
||||
Reference in new issue
Block a user