fix
This commit is contained in:
parent
187b738f2d
commit
ddac05de61
@ -1,49 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -e # Exit immediately if a command exits with a non-zero status.
|
||||
set -o pipefail # Causes a pipeline to return the exit status of the last command in the pipe that failed.
|
||||
# set -x # Uncomment for verbose debugging
|
||||
|
||||
# vars via Semaphore UI
|
||||
MAIN_BR="${MAIN_BR:-main}" # Branche du dépôt main_playbooks
|
||||
ENV="${ENV:-staging}" # Nom de l'environnement (staging, prod, etc.)
|
||||
ENV_BR="${ENV_BR:-test_feature}" # Branche des fichiers d'env
|
||||
PLAYBOOK_FILE="${PLAYBOOK_FILE:-base.yaml}" # Nom du fichier playbook dans /playbooks/
|
||||
MAIN_BR="${MAIN_BR:-main}"
|
||||
ENV="${ENV:-staging}"
|
||||
ENV_BR="${ENV_BR:-test_feature}"
|
||||
PLAYBOOK_FILE="${PLAYBOOK_FILE:-base.yaml}"
|
||||
|
||||
REPO_CORE="git@git.felcloud.io:felcloud/ansible_core_init_ansible.git"
|
||||
REPO_ENV="git@git.felcloud.io:felcloud/ansible_env_staging.git"
|
||||
|
||||
# Setup SSH and known_hosts
|
||||
echo "[INFO] Setting up SSH environment..."
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
|
||||
# Add git.felcloud.io to known_hosts to avoid interactive prompt
|
||||
# Add git.felcloud.io to known_hosts (good practice, but we'll override for clone if needed)
|
||||
echo "[INFO] Adding git.felcloud.io to known_hosts..."
|
||||
ssh-keyscan git.felcloud.io >> ~/.ssh/known_hosts
|
||||
ssh-keyscan git.felcloud.io >> ~/.ssh/known_hosts || echo "[WARN] ssh-keyscan failed but continuing."
|
||||
chmod 644 ~/.ssh/known_hosts
|
||||
|
||||
# Debug SSH keys
|
||||
echo "[DEBUG] Available SSH keys:"
|
||||
echo "[DEBUG] Content of ~/.ssh/known_hosts after keyscan:"
|
||||
cat ~/.ssh/known_hosts || echo "[WARN] Could not cat known_hosts"
|
||||
|
||||
# Debug SSH keys available from Semaphore Secrets
|
||||
echo "[DEBUG] Available SSH keys in ~/.ssh:"
|
||||
ls -la ~/.ssh
|
||||
|
||||
# Define the SSH command for Git to use
|
||||
# This will bypass strict host key checking and not use the system known_hosts file for these specific git commands.
|
||||
# It will still use any identity files (private keys) found in ~/.ssh/
|
||||
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
|
||||
|
||||
# 1/Cloner les dépôts nécessaires:
|
||||
echo "[INFO] Cloning repositories..."
|
||||
git clone git@git.felcloud.io:felcloud/ansible_core_init_ansible.git
|
||||
git clone git@git.felcloud.io:felcloud/ansible_env_staging.git
|
||||
echo "[INFO] Cloning repositories using GIT_SSH_COMMAND..."
|
||||
echo "[INFO] Cloning $REPO_CORE on branch $ENV_BR..."
|
||||
git clone --branch "$ENV_BR" "$REPO_CORE" ansible_core_init_ansible
|
||||
|
||||
echo "[INFO] Cloning $REPO_ENV..."
|
||||
# If ansible_env_staging also needs a specific branch:
|
||||
# git clone --branch "<some_branch_for_env>" "$REPO_ENV" ansible_env_staging
|
||||
git clone "$REPO_ENV" ansible_env_staging
|
||||
|
||||
# Unset GIT_SSH_COMMAND if you want subsequent ssh operations to use default behavior
|
||||
# unset GIT_SSH_COMMAND
|
||||
|
||||
cd ansible_core_init_ansible
|
||||
git checkout "$ENV_BR"
|
||||
# git checkout "$ENV_BR" # Already done by --branch in clone
|
||||
|
||||
# 2/Build local de l’image Docker admin:
|
||||
echo "[INFO] Building Docker image locally..."
|
||||
# Build context is the current directory: ./ansible_core_init_ansible
|
||||
docker build --no-cache --build-arg branch=fix_packages_dependencies -t ansible-pulumi:local .
|
||||
cd .. # Go back to the parent directory (where ansible_env_staging also is)
|
||||
|
||||
# 3/Lancer le conteneur admin avec le playbook choisi:
|
||||
echo "[INFO] Running the admin container with playbook: $PLAYBOOK_FILE"
|
||||
docker run --rm -it \
|
||||
-v "$(pwd)/../ansible_env_staging:/home/cloud/ansible_env_staging" \
|
||||
-v "$(pwd)/ansible_env_staging:/home/cloud/ansible_env_staging" \
|
||||
-e MAIN_BR="$MAIN_BR" \
|
||||
-e ENV="$ENV" \
|
||||
-e ENV_BR="$ENV_BR" \
|
||||
ansible-pulumi:local bash -c "
|
||||
cd /home/cloud/ansible-pulumi && \
|
||||
source /home/cloud/venv/bin/activate && \
|
||||
set -e; \
|
||||
echo '[CONTAINER] Current directory: \$(pwd)'; \
|
||||
echo '[CONTAINER] Listing /home/cloud:'; ls -la /home/cloud; \
|
||||
echo '[CONTAINER] Listing /home/cloud/ansible_env_staging:'; ls -la /home/cloud/ansible_env_staging; \
|
||||
echo '[CONTAINER] Activating venv...'; \
|
||||
source /home/cloud/venv/bin/activate; \
|
||||
echo '[CONTAINER] Changing to playbook directory /home/cloud/ansible-pulumi...'; \
|
||||
cd /home/cloud/ansible-pulumi; \
|
||||
echo '[CONTAINER] Running ansible-playbook...'; \
|
||||
ansible-playbook playbooks/${PLAYBOOK_FILE} -i /home/cloud/ansible_env_staging/hosts"
|
||||
|
||||
|
||||
echo "[INFO] Task completed."
|
||||
|
Loading…
Reference in New Issue
Block a user