-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger-awx-tag.sh
More file actions
75 lines (65 loc) · 2.2 KB
/
trigger-awx-tag.sh
File metadata and controls
75 lines (65 loc) · 2.2 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# A script to trigger an AWX Job Template given the following
# on the command-line: -
#
# - a container image tag (i.e. '1.0.0')
# - the AWX Job Template variable to use for the tag (i.e. 'image_tag')
# - a Job Template name to run (i.e. 'Bother')
#
# Usage: ./trigger-awx-tag.sh <TAG> <JOB-TAG-VARIABLE> <JOB-NAME>
#
# This assumes the 'awxkit' utility is available,
# usually installed via a requirements file prior to our execution.
#
# As this script is normally executed from within a CI framework
# it also uses environment variables to control the script's actions
# rather than overload the command-line. Namely: -
#
# - AWX_HOST The server URL (i.e. https://example.com/awx)
# - AWX_USER The name of a user that can execute the Job
# - AWX_USER_PASSWORD The user's password
#
# Note: Travis can encrypt the variables but avoid encrypting AWX_JOB_NAME
# and make sure you use double-quotes if there are any spaces in the
# Job name.
#
# The script disables any input that the AWX Job Template may request and
# then waits for the Job to complete.
#
# On error or if the Job Template is not found the script exits with code 1.
set -eo pipefail
: "${AWX_HOST?Need to set AWX_HOST}"
: "${AWX_USER?Need to set AWX_USER}"
: "${AWX_USER_PASSWORD?Need to set AWX_USER_PASSWORD}"
if [[ -z "$1" ]]; then
echo "ERROR: Missing tag"
echo "Usage: trigger-awx-tag.sh <tag> <tag-variable> <job-name>"
exit 1
fi
if [[ -z "$2" ]]; then
echo "ERROR: Missing AWX tag variable"
echo "Usage: trigger-awx-tag.sh <tag> <tag-variable> <job-name>"
exit 1
fi
if [[ -z "$3" ]]; then
echo "ERROR: Missing Job name"
echo "Usage: trigger-awx-tag.sh <tag> <tag-variable> <job-name>"
exit 1
fi
TAG=$1
TAG_VARIABLE=$2
TEMPLATE=$3
EXTRA_VARS={\"${TAG_VARIABLE}\":\"${TAG}\"}
echo "AWX_VERSION=`awx --version`"
echo "EXTRA_VARS=${EXTRA_VARS}"
echo "TEMPLATE='${TEMPLATE}'"
echo "AWX_HOST=${AWX_HOST}"
echo "AWX_USER=${AWX_USER}"
echo "AWX_USER_PASSWORD=${AWX_USER_PASSWORD}"
echo "Running 'awx job_templates launch' and monitoring..."
awx job_templates launch "${TEMPLATE}" \
-e ${EXTRA_VARS} \
--conf.host ${AWX_HOST} \
--conf.username ${AWX_USER} \
--conf.password ${AWX_USER_PASSWORD} \
--monitor