forked from ashish-k-s/NovelloShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-script_stack-list.sh
executable file
·44 lines (42 loc) · 1.44 KB
/
sample-script_stack-list.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Tasks performed by associated tower job:
# Execute command: openstack stack list
# Redirect command output in one file
# Accept all possible args for stack list command in the form of string
# Accept one more string as argument which can be used as filename to redirect output
# Copy the output file to remote host
# This script will cat the file copied by tower job to get the output in exact same form
# as the output provided by running command on console
TOWER_HOST=https://tower.engineering.redhat.com
TOWER_OAUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TOWER_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
JOBID=5942
if [[ $# -eq 0 ]]
then
echo -e "insufficient arg"
exit 1
fi
file=$1
$(sudo -u toweruser rm /tmp/$file > /dev/null 2>&1)
shift
echo -e "Probing list of labs using tower job, this may take some time..."
if [[ $# -eq 0 ]]
then
#echo -e "No args"
#cmd="awx --conf.host $TOWER_HOST --conf.token $TOWER_TOKEN job_templates launch $JOBID --monitor -f human"
cmd="awx --conf.host $TOWER_HOST --conf.token $TOWER_TOKEN job_templates launch $JOBID --extra_vars '{job_output_file: $file}' --monitor -f human"
else
arr=($@)
for var in "$@"
do
if [[ $var == -* ]]
then
args="$args $var"
else
args="$args \"$var\""
fi
done
cmd="awx --conf.host $TOWER_HOST --conf.token $TOWER_TOKEN job_templates launch $JOBID --extra_vars '{job_output_file: $file, stack_list_args: $args}' --monitor -f human"
fi
eval $cmd > /dev/null 2>&1
#eval $cmd
cat /tmp/$file