server_init/scripts/03_run_playbook.sh

18 lines
982 B
Bash
Raw Normal View History

#!/bin/bash
set -e
echo "=== Phase 3: Copying files and running playbook ==="
rsync -az --exclude '.git' "$SCRIPT_DIR/" "$NEW_USER@pangolin.$HOST:~/server_init/"
EXTRA_VARS="base_domain=$HOST"
EXTRA_VARS="$EXTRA_VARS ssh_pubkey=\"$PUBKEY\""
EXTRA_VARS="$EXTRA_VARS juicefs_s3_endpoint=$JUICEFS_S3_ENDPOINT"
EXTRA_VARS="$EXTRA_VARS juicefs_s3_bucket=$JUICEFS_S3_BUCKET"
EXTRA_VARS="$EXTRA_VARS juicefs_s3_access_key=$JUICEFS_S3_ACCESS_KEY"
EXTRA_VARS="$EXTRA_VARS juicefs_s3_secret_key=$JUICEFS_S3_SECRET_KEY"
EXTRA_VARS="$EXTRA_VARS juicefs_cache_size=$JUICEFS_CACHE_SIZE"
ssh -t "$NEW_USER@pangolin.$HOST" \
"bash -c 'sudo locale-gen en_US.UTF-8 && if ! command -v ansible &>/dev/null; then echo \"Installing Ansible...\"; sudo apt-get update && sudo apt-get install -y ansible-core python3-pip; fi && echo \"Running Ansible playbook...\" && cd ~/server_init && LC_ALL=en_US.UTF-8 ansible-playbook -i localhost, -c local playbook.yml -e \"$EXTRA_VARS\" --ask-become-pass'"