summaryrefslogtreecommitdiff
path: root/playbooks/roles/ci/templates/volumes/laminar/jobs/playbook.run
blob: 181a050e51619c89eceffeab16ef0419e73b6321 (plain)
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
#!/bin/bash
# usage: laminarc queue playbook remote="ssh://src.liz.coffee:2222/infra" playbooks="deploy.yml playbooks/labdns.yml"

set -e

declare -a args=("$remote" "$playbooks")
for arg in "${args[@]}"
do
  if [[ ! "$arg" =~ ^[[:alnum:]:_\ \.\/\-]*$ ]]; then
    echo "Invalid argument format. Don't be sneaky snek (-_-)."
    exit 1
  fi
done

log "Cloning remote $remote"
r=$(echo "ansible-$(date --iso-8601=seconds)")
git clone "$remote" "$r" && cd "$r"

get_secret "ansible_secrets" | jq -r '.notes' > secrets.yml
private_key=$(get_secret "ssh_key" | jq -r '.notes')

env -i HOME="$HOME" ssh-agent bash -c "ssh-add <(echo \"$private_key\") && ansible-playbook -e @secrets.yml $playbooks"

cd -
rm -rf "$r"