deploiement de snowshare

This commit is contained in:
2026-07-30 11:47:24 +00:00
parent b170c71db0
commit cc73e4214a
4 changed files with 196 additions and 0 deletions

View File

@@ -218,6 +218,29 @@
delegate_to: localhost
become: false
- name: Supprimer l ancienne cle SSH connue
known_hosts:
name: "{{ lxc_ip_address }}"
state: absent
delegate_to: localhost
become: false
- name: Scanner la nouvelle cle SSH du LXC
command: ssh-keyscan -H {{ lxc_ip_address }}
register: lxc_ssh_keyscan
changed_when: false
delegate_to: localhost
become: false
- name: Ajouter la nouvelle cle SSH du LXC dans known_hosts
known_hosts:
name: "{{ lxc_ip_address }}"
key: "{{ item }}"
state: present
loop: "{{ lxc_ssh_keyscan.stdout_lines }}"
delegate_to: localhost
become: false
# Ajout automatique du nouveau LXC dans inventory/hosts.ini.
#
# blockinfile evite les doublons:

View File

@@ -0,0 +1,118 @@
---
# Playbook: deploy-snowshare.yml
#
# But:
# - Deployer Snowshare dans le LXC snowshare
# - Copier le docker-compose.yml depuis Git
# - Generer .env.runtime si absent
# - Creer un lien .env pour Docker Compose
# - Demarrer la stack Docker Compose
# - Verifier que le port 3000 repond
#
# Important:
# - Les secrets ne doivent pas etre dans Git
# - Le fichier .env.runtime reste sur le LXC
- name: Deployer Snowshare
hosts: snowshare_servers
become: true
gather_facts: false
vars:
stack_name: snowshare
stack_path: /opt/stacks/snowshare
compose_source: "{{ playbook_dir }}/../services/snowshare/docker-compose.yml"
snowshare_domain: snowshare.thomasmlg.fr
tasks:
- name: Verifier que Docker est installe
command: docker --version
changed_when: false
- name: Verifier que Docker Compose est installe
command: docker compose version
changed_when: false
- name: Creer le dossier de la stack
file:
path: "{{ stack_path }}"
state: directory
owner: root
group: root
mode: "0750"
- name: Generer le fichier env runtime si absent
shell: |
set -e
umask 077
if [ ! -f "{{ stack_path }}/.env.runtime" ]; then
POSTGRES_PASSWORD="$(openssl rand -hex 32)"
NEXTAUTH_SECRET="$(openssl rand -hex 32)"
{
printf 'POSTGRES_USER=snowshare\n'
printf 'POSTGRES_PASSWORD=%s\n' "$POSTGRES_PASSWORD"
printf 'POSTGRES_DB=snowshare\n'
printf 'DATABASE_URL=postgres://snowshare:%s@db:5432/snowshare\n' "$POSTGRES_PASSWORD"
printf 'NEXTAUTH_URL=https://{{ snowshare_domain }}\n'
printf 'NEXTAUTH_SECRET=%s\n' "$NEXTAUTH_SECRET"
printf 'ALLOW_SIGNUP=true\n'
} > "{{ stack_path }}/.env.runtime"
fi
chown root:root "{{ stack_path }}/.env.runtime"
chmod 600 "{{ stack_path }}/.env.runtime"
args:
executable: /bin/bash
no_log: true
changed_when: true
- name: Creer le lien env pour Docker Compose
file:
src: "{{ stack_path }}/.env.runtime"
dest: "{{ stack_path }}/.env"
state: link
owner: root
group: root
- name: Copier le fichier Docker Compose
copy:
src: "{{ compose_source }}"
dest: "{{ stack_path }}/docker-compose.yml"
owner: root
group: root
mode: "0644"
- name: Valider la configuration Docker Compose
command: docker compose config
args:
chdir: "{{ stack_path }}"
changed_when: false
- name: Telecharger les images Docker
command: docker compose pull
args:
chdir: "{{ stack_path }}"
- name: Demarrer la stack Snowshare
command: docker compose up -d
args:
chdir: "{{ stack_path }}"
- name: Attendre le port Snowshare
wait_for:
host: 127.0.0.1
port: 3000
timeout: 180
- name: Afficher les conteneurs de la stack
command: docker compose ps
args:
chdir: "{{ stack_path }}"
register: compose_ps
changed_when: false
- name: Afficher le statut Docker Compose
debug:
var: compose_ps.stdout_lines