Actualiser synology_upgrade_ssh.yml

This commit is contained in:
l.covela 2026-01-07 12:46:03 +01:00
parent 697e27fb59
commit b1153c1273
1 changed files with 53 additions and 43 deletions

View File

@ -4,18 +4,13 @@
gather_facts: false gather_facts: false
vars: vars:
# Si tu veux aussi lancer l'installation après le download do_install: false # true si tu veux lancer l'install après download
do_install: false do_reboot: false # true si tu veux reboot après install
# Si tu veux reboot après install (DSM redémarre parfois tout seul selon méthode)
do_reboot: false
# Timeout long pour les téléchargements
download_timeout: 7200 download_timeout: 7200
tasks: tasks:
# ------------------------------------------------------------ # ------------------------------------------------------------
# 0) Vérifs / infos système (DSM version) # 0) Version DSM
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Lire la version DSM (DSM6/DSM7) - name: Lire la version DSM (DSM6/DSM7)
ansible.builtin.shell: | ansible.builtin.shell: |
@ -36,9 +31,9 @@
var: dsm_version.stdout_lines var: dsm_version.stdout_lines
# ------------------------------------------------------------ # ------------------------------------------------------------
# 1) Trouver synoupgrade (chemins Synology) # 1) Trouver synoupgrade
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Détecter synoupgrade (sans [ ]) - name: Détecter synoupgrade
ansible.builtin.shell: | ansible.builtin.shell: |
if command -v synoupgrade >/dev/null 2>&1; then if command -v synoupgrade >/dev/null 2>&1; then
command -v synoupgrade command -v synoupgrade
@ -67,38 +62,38 @@
- name: Enregistrer le binaire synoupgrade - name: Enregistrer le binaire synoupgrade
ansible.builtin.set_fact: ansible.builtin.set_fact:
synoupgrade_bin: "{{ (synoupgrade_path.stdout | trim) }}" synoupgrade_bin: "{{ synoupgrade_path.stdout | trim }}"
- name: Fail si synoupgrade introuvable - name: Fail si synoupgrade introuvable
ansible.builtin.fail: ansible.builtin.fail:
msg: "synoupgrade introuvable sur ce NAS (DSM). stdout='{{ synoupgrade_path.stdout | trim }}'" msg: "synoupgrade introuvable sur ce NAS. stdout='{{ synoupgrade_path.stdout | trim }}'"
when: synoupgrade_bin == "MISSING" or synoupgrade_bin == "" when: synoupgrade_bin in ["", "MISSING"]
- name: Debug synoupgrade - name: Debug synoupgrade
ansible.builtin.debug: ansible.builtin.debug:
msg: "synoupgrade détecté: {{ synoupgrade_bin }}" msg: "synoupgrade détecté: {{ synoupgrade_bin }}"
# ------------------------------------------------------------ # ------------------------------------------------------------
# 2) Check si une MAJ DSM est dispo # 2) Check si une MAJ est dispo (best effort)
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Check mise à jour disponible (best effort) - name: Check mise à jour disponible (best effort)
ansible.builtin.shell: | ansible.builtin.shell: |
# Selon DSM, différentes options existent.
# On essaye plusieurs modes sans échouer le playbook.
set +e set +e
SYNO="{{ synoupgrade_bin }}"
"{{ synoupgrade_bin }}" --help 2>/dev/null | head -n 50 echo "---- HELP ----"
"$SYNO" --help 2>/dev/null | head -n 80
echo "---- TRY: check ----" echo "---- TRY: check ----"
"{{ synoupgrade_bin }}" check 2>&1 "$SYNO" check 2>&1
rc1=$? rc1=$?
echo "---- TRY: --check ----" echo "---- TRY: --check ----"
"{{ synoupgrade_bin }}" --check 2>&1 "$SYNO" --check 2>&1
rc2=$? rc2=$?
echo "---- TRY: --status ----" echo "---- TRY: --status ----"
"{{ synoupgrade_bin }}" --status 2>&1 "$SYNO" --status 2>&1
rc3=$? rc3=$?
echo "RCs: check=$rc1 --check=$rc2 --status=$rc3" echo "RCs: check=$rc1 --check=$rc2 --status=$rc3"
@ -112,17 +107,15 @@
ansible.builtin.debug: ansible.builtin.debug:
var: check_out.stdout_lines var: check_out.stdout_lines
# Heuristique : si on voit des mots indiquant une MAJ dispo
- name: Déterminer si une mise à jour semble dispo (heuristique) - name: Déterminer si une mise à jour semble dispo (heuristique)
ansible.builtin.set_fact: ansible.builtin.set_fact:
update_available: >- update_available: >-
{{ {{
( (
(check_out.stdout | lower).find('update') != -1 (check_out.stdout | lower).find('available') != -1
or (check_out.stdout | lower).find('update') != -1
or (check_out.stdout | lower).find('upgrade') != -1 or (check_out.stdout | lower).find('upgrade') != -1
or (check_out.stdout | lower).find('available') != -1
or (check_out.stdout | lower).find('download') != -1 or (check_out.stdout | lower).find('download') != -1
or (check_out.stdout | lower).find('new') != -1
or (check_out.stdout | lower).find('télécharg') != -1 or (check_out.stdout | lower).find('télécharg') != -1
or (check_out.stdout | lower).find('dispon') != -1 or (check_out.stdout | lower).find('dispon') != -1
) )
@ -137,18 +130,23 @@
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Télécharger la mise à jour DSM (best effort) - name: Télécharger la mise à jour DSM (best effort)
ansible.builtin.shell: | ansible.builtin.shell: |
set -e set +e
# On tente plusieurs syntaxes selon versions DSM. SYNO="{{ synoupgrade_bin }}"
# La commande correcte dépend du modèle/DSM.
# L'idée: déclencher le download depuis les dépôts Synology. echo "---- TRY: download ----"
# "$SYNO" download 2>&1
# Tentative 1: rc1=$?
"{{ synoupgrade_bin }}" download || true
# Tentative 2: echo "---- TRY: --download ----"
"{{ synoupgrade_bin }}" --download || true "$SYNO" --download 2>&1
# Tentative 3: rc2=$?
"{{ synoupgrade_bin }}" download --start || true
echo "Download commands sent." echo "---- TRY: download --start ----"
"$SYNO" download --start 2>&1
rc3=$?
echo "RCs: download=$rc1 --download=$rc2 download--start=$rc3"
exit 0
args: args:
executable: /bin/bash executable: /bin/bash
register: dl_out register: dl_out
@ -166,15 +164,27 @@
when: not (update_available | bool) when: not (update_available | bool)
# ------------------------------------------------------------ # ------------------------------------------------------------
# 4) Optionnel : installer après téléchargement # 4) Optionnel : installer
# ------------------------------------------------------------ # ------------------------------------------------------------
- name: Lancer l'installation DSM (optionnel) - name: Installer DSM (optionnel)
ansible.builtin.shell: | ansible.builtin.shell: |
set -e set +e
"{{ synoupgrade_bin }}" start || true SYNO="{{ synoupgrade_bin }}"
"{{ synoupgrade_bin }}" --start || true
"{{ synoupgrade_bin }}" upgrade || true echo "---- TRY: start ----"
echo "Install commands sent." "$SYNO" start 2>&1
rc1=$?
echo "---- TRY: --start ----"
"$SYNO" --start 2>&1
rc2=$?
echo "---- TRY: upgrade ----"
"$SYNO" upgrade 2>&1
rc3=$?
echo "RCs: start=$rc1 --start=$rc2 upgrade=$rc3"
exit 0
args: args:
executable: /bin/bash executable: /bin/bash
register: install_out register: install_out