You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.2 KiB
YAML
80 lines
2.2 KiB
YAML
|
4 months ago
|
# ==============================================
|
||
|
|
# Pipeline Concourse - Déploiement Automatique
|
||
|
|
# ==============================================
|
||
|
|
# Surveille le repo Git et déploie automatiquement
|
||
|
|
|
||
|
|
resource_types: []
|
||
|
|
|
||
|
|
resources:
|
||
|
|
# Repo Git local (polling toutes les 30 secondes)
|
||
|
|
- name: repo
|
||
|
|
type: git
|
||
|
|
icon: gitlab
|
||
|
|
check_every: 30s
|
||
|
|
source:
|
||
|
|
uri: https://forge.gwenaelremond.fr/romain/ansiblenginx.git
|
||
|
|
branch: main
|
||
|
|
|
||
|
|
jobs:
|
||
|
|
# Job principal : Déploiement automatique
|
||
|
|
- name: deploy-bricoloc
|
||
|
|
plan:
|
||
|
|
# 1. Récupère le code depuis Git
|
||
|
|
- get: repo
|
||
|
|
trigger: true # Déclenche automatiquement sur changement
|
||
|
|
|
||
|
|
# 2. Déploie sur le VPS
|
||
|
|
- task: deploy-to-vps
|
||
|
|
config:
|
||
|
|
platform: linux
|
||
|
|
|
||
|
|
image_resource:
|
||
|
|
type: registry-image
|
||
|
|
source:
|
||
|
|
repository: python
|
||
|
|
tag: "3.11-slim"
|
||
|
|
|
||
|
|
inputs:
|
||
|
|
- name: repo
|
||
|
|
|
||
|
|
params:
|
||
|
|
ssh_private_key: ((ssh_private_key))
|
||
|
|
vps_host: ((vps_host))
|
||
|
|
vps_user: ((vps_user))
|
||
|
|
|
||
|
|
run:
|
||
|
|
path: /bin/bash
|
||
|
|
args:
|
||
|
|
- -exc
|
||
|
|
- |
|
||
|
|
# Installer les dépendances
|
||
|
|
apt-get update && apt-get install -y openssh-client rsync sshpass
|
||
|
|
pip install ansible
|
||
|
|
|
||
|
|
# Configurer SSH
|
||
|
|
mkdir -p ~/.ssh
|
||
|
|
echo "$ssh_private_key" > ~/.ssh/id_rsa
|
||
|
|
chmod 600 ~/.ssh/id_rsa
|
||
|
|
ssh-keyscan -H $vps_host >> ~/.ssh/known_hosts 2>/dev/null
|
||
|
|
|
||
|
|
cd repo
|
||
|
|
|
||
|
|
# Créer l'inventaire dynamique
|
||
|
|
cat > inventory.yml << EOF
|
||
|
|
all:
|
||
|
|
hosts:
|
||
|
|
vps1:
|
||
|
|
ansible_host: $vps_host
|
||
|
|
ansible_user: $vps_user
|
||
|
|
ansible_ssh_private_key_file: ~/.ssh/id_rsa
|
||
|
|
children:
|
||
|
|
webservers:
|
||
|
|
hosts:
|
||
|
|
vps1:
|
||
|
|
EOF
|
||
|
|
|
||
|
|
# Lancer le playbook Ansible
|
||
|
|
ansible-playbook -i inventory.yml playbook.yml
|
||
|
|
|
||
|
|
echo "✅ Déploiement terminé sur $vps_host"
|