117 lines
3.2 KiB
YAML
117 lines
3.2 KiB
YAML
---
|
|
# Playbook: deploy-passwordpusher.yml
|
|
#
|
|
# But:
|
|
# - Copier le docker-compose.yml Password Pusher sur le LXC
|
|
# - Generer le fichier .env.runtime sur le LXC si absent
|
|
# - Garder les secrets hors Git
|
|
# - Demarrer la stack Docker Compose
|
|
# - Verifier que le port 5100 repond
|
|
|
|
- name: Deployer Password Pusher
|
|
hosts: passwordpusher_servers
|
|
become: true
|
|
gather_facts: false
|
|
|
|
vars_prompt:
|
|
- name: smtp_address
|
|
prompt: "SMTP address"
|
|
private: false
|
|
|
|
- name: smtp_user
|
|
prompt: "SMTP username"
|
|
private: false
|
|
|
|
- name: smtp_password
|
|
prompt: "SMTP password"
|
|
private: true
|
|
|
|
vars:
|
|
stack_name: passwordpusher
|
|
stack_path: /opt/stacks/passwordpusher
|
|
compose_source: "{{ playbook_dir }}/../services/passwordpusher/docker-compose.yml"
|
|
|
|
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: Creer le dossier de stockage
|
|
file:
|
|
path: "{{ stack_path }}/storage"
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
|
|
- name: Generer le fichier env runtime si absent
|
|
shell: |
|
|
set -e
|
|
umask 077
|
|
|
|
if [ ! -f "{{ stack_path }}/.env.runtime" ]; then
|
|
SECRET_KEY_BASE="$(openssl rand -hex 64)"
|
|
PWPUSH_MASTER_KEY="$(openssl rand -hex 32)"
|
|
|
|
{
|
|
printf 'SECRET_KEY_BASE=%s\n' "$SECRET_KEY_BASE"
|
|
printf 'PWPUSH_MASTER_KEY=%s\n' "$PWPUSH_MASTER_KEY"
|
|
printf 'PWP__MAIL__SMTP_ADDRESS=%s\n' "{{ smtp_address }}"
|
|
printf 'PWP__MAIL__SMTP_USER_NAME=%s\n' "{{ smtp_user }}"
|
|
printf 'PWP__MAIL__SMTP_PASSWORD=%s\n' "{{ smtp_password }}"
|
|
} > "{{ 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: Copier le fichier Docker Compose
|
|
copy:
|
|
src: "{{ compose_source }}"
|
|
dest: "{{ stack_path }}/docker-compose.yml"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
|
|
- name: Telecharger les images Docker
|
|
command: docker compose pull
|
|
args:
|
|
chdir: "{{ stack_path }}"
|
|
|
|
- name: Demarrer la stack Password Pusher
|
|
command: docker compose up -d
|
|
args:
|
|
chdir: "{{ stack_path }}"
|
|
|
|
- name: Attendre le port Password Pusher
|
|
wait_for:
|
|
host: 127.0.0.1
|
|
port: 5100
|
|
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 |