Skip to content

Commit

Permalink
import filter inventory script
Browse files Browse the repository at this point in the history
  • Loading branch information
tosmi committed Oct 12, 2021
1 parent da4811a commit 1b5a41d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
34 changes: 34 additions & 0 deletions filter_inventory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

[ -z "$STAGE_ENV" ] && exit 1

WAVE=${WAVE:-ALL}
WAVE1_HOSTS=3

inventory=$(cat inventory.txt)
# curl...

case "$WAVE" in
ANSIBLETEST)
inventory=$(echo "$inventory" | grep wally)
echo $inventory
;;
WAVE1)
inventory=$(echo "$inventory" | head -"$WAVE1_HOSTS")
;;
esac

inventory=$(sed 's/^/"/g;s/$/"/g' <<< $inventory)
inventory=$(sed ':a;N;$!ba;s/\n/,/g' <<< $inventory)

cat << EOF
{
"ANSIBLE_TEST": {
"hosts": [$inventory],
"vars": {
"var1": true
},
"children": []
}
}
EOF
7 changes: 7 additions & 0 deletions inventory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
host1
host2
host3
host4
wally1
wally2
wally3

0 comments on commit 1b5a41d

Please sign in to comment.