Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions environments/manager/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ command -v ansible-galaxy >/dev/null 2>&1 || { echo >&2 "ansible-galaxy not inst
ANSIBLE_USER=${ANSIBLE_USER:-dragon}
CLEANUP=${CLEANUP:-false}

cleanup () {
if [[ $CLEANUP == "true" ]]; then
rm id_rsa.operator
rm -rf "$VENV_PATH"
fi
}
trap cleanup ERR EXIT

if [[ $INSTALL_ANSIBLE_ROLES == "true" ]]; then
ansible-galaxy collection install -f "git+https://github.com/osism/ansible-collection-commons,${ANSIBLE_COLLECTION_COMMONS_VERSION}"
ansible-galaxy collection install -f "git+https://github.com/osism/ansible-collection-services,${ANSIBLE_COLLECTION_SERVICES_VERSION}"
Expand All @@ -54,7 +62,7 @@ if [[ ! -e id_rsa.operator ]]; then
-i localhost, \
-e @../secrets.yml \
-e "keypair_dest=$(pwd)/id_rsa.operator" \
osism.manager.keypair "$@"
osism.manager.keypair "$@" || exit $?
fi

if [[ $playbook == "k8s" || $playbook == "netbox" || $playbook == "traefik" ]]; then
Expand All @@ -71,7 +79,7 @@ if [[ $playbook == "k8s" || $playbook == "netbox" || $playbook == "traefik" ]];
-e @configuration.yml \
-e @secrets.yml \
-u "$ANSIBLE_USER" \
osism.manager."$playbook" "$@"
osism.manager."$playbook" "$@" || exit $?
elif [[ $playbook == "operator" ]]; then
if [[ $ANSIBLE_ASK_PASS == "True" ]]; then
ansible-playbook \
Expand All @@ -83,7 +91,7 @@ elif [[ $playbook == "operator" ]]; then
-e @configuration.yml \
-e @secrets.yml \
-u "$ANSIBLE_USER" \
osism.manager."$playbook" "$@"
osism.manager."$playbook" "$@" || exit $?
else
ansible-playbook \
--private-key id_rsa.operator \
Expand All @@ -95,7 +103,7 @@ elif [[ $playbook == "operator" ]]; then
-e @configuration.yml \
-e @secrets.yml \
-u "$ANSIBLE_USER" \
osism.manager."$playbook" "$@"
osism.manager."$playbook" "$@" || exit $?
fi
else
ansible-playbook \
Expand All @@ -108,10 +116,5 @@ else
-e @configuration.yml \
-e @secrets.yml \
-u "$ANSIBLE_USER" \
osism.manager."$playbook" "$@"
fi

if [[ $CLEANUP == "true" ]]; then
rm id_rsa.operator
rm -rf "$VENV_PATH"
osism.manager."$playbook" "$@" || exit $?
fi
7 changes: 7 additions & 0 deletions releasenotes/notes/pass-exit-code-0f5f47b31efe5e2b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
features:
- |
In the `run.sh` script in `environments/manager`, the execution is now interrupted
directly in the event of an error in an Ansible run and the exit code is passed through.
A trap is used to keep things clean as before (only if a cleanup was requested with
`CLEANUP=True`).