#!/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"