-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-ansible-execution-environment
executable file
·44 lines (36 loc) · 1.64 KB
/
build-ansible-execution-environment
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
#!/bin/bash
set -e
HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
. "$HERE/_env"
. "$HERE/_trap"
not_root
# Want to install a Python library to use in your playbook?
#
# Things that don't work:
#
# 1) The "roles/requirements.yaml" file is ignored for manual projects in "/var/lib/awx/projects/".
# Maybe it only works for SCM projects? Anyway, it can be used to install Galaxy roles, but not
# individual packages.
#
# 2) We can put libraries in a project's local "module_utils" directory, which are then merged into
# the system "ansible.module_utils" package. But then they would have to internally also import
# from "ansible.module_utils...", which would require coding them specifically for that. So we
# can't just put arbitrary source code here.
#
# 3) Using "--custom_virtualenv" when creating a project seems to be ignored.
#
# The only solution that works is the right one: creating a proper Ansible execution environment.
NAME=tko-ansible-execution-environment
TAG=${TAG:-$DOCKER_REGISTRY}
cat "$ROOT/assets/ansible/builder/_execution-environment.yaml" |
ALPINE_VERSION=$ALPINE_VERSION ALPINE_PYTHON_VERSION=$ALPINE_PYTHON_VERSION ANSIBLE_CORE_VERSION=$ANSIBLE_CORE_VERSION ANSIBLE_RUNNER_VERSION=$ANSIBLE_RUNNER_VERSION \
envsubst > "$ROOT/assets/ansible/builder/execution-environment.yaml"
mkdir --parents "$ROOT/work/"
rm --recursive --force "$ROOT/work/ansible-builder/"
"$PYTHON_ENV/bin/ansible-builder" build \
--file="$ROOT/assets/ansible/builder/execution-environment.yaml" \
--context="$ROOT/work/ansible-builder" \
--container-runtime=docker \
--tag="$NAME"
docker image tag "$NAME" "$TAG/$NAME"
docker push "$TAG/$NAME"