#!/bin/sh set -eu record=$1 environment=$2 operation=${3:-deploy} case "$record" in build/delivery/releases/*.json|delivery/releases/*.json) ;; *) echo 'Release record must be in the release metadata directory' >&2; exit 1 ;; esac python3 delivery/ci/release.py verify "$record" --environment "$environment" config=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["configuration_commit"])' "$record") scratch=$(mktemp -d) trap 'rm -rf "$scratch"' EXIT # Recover both playbook and template from the configuration recorded with this image. git archive "$config" delivery/ansible | tar -x -C "$scratch" : "${DEPLOY_KEY:?bind the deployment SSH key as a Jenkins file credential}" : "${DEPLOY_KNOWN_HOSTS:?bind the verified known_hosts as a Jenkins file credential}" export ANSIBLE_HOST_KEY_CHECKING=True export ANSIBLE_SSH_ARGS="-o BatchMode=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile=$DEPLOY_KNOWN_HOSTS" export ANSIBLE_PRIVATE_KEY_FILE="$DEPLOY_KEY" ansible-playbook -i "$scratch/delivery/ansible/inventory.ini" \ "$scratch/delivery/ansible/deploy.yml" --syntax-check -e "@$record" python3 delivery/ci/run-ansible.py "$record" "$operation" \ -i "$scratch/delivery/ansible/inventory.ini" \ "$scratch/delivery/ansible/deploy.yml" -e "@$record"