Actualiser test.yml

This commit is contained in:
l.covela 2026-01-07 12:50:54 +01:00
parent b1153c1273
commit a251c55ca8
1 changed files with 262 additions and 17 deletions

279
test.yml
View File

@ -1,23 +1,268 @@
---
- hosts: synology
- name: Synology DSM - Découverte outils MAJ + tentative download/install (SSH)
hosts: synology
gather_facts: false
vars:
do_install: false # true => tente de lancer l'installation après download
do_reboot: false # true => reboot après install
command_timeout: 120
tasks:
- name: Inspect shell env on Synology
ansible.builtin.raw: |
echo "WHOAMI=$(whoami 2>/dev/null || true)"
echo "SHELL0=$0"
echo "PATH=$PATH"
echo "which_sh=$(command -v sh 2>/dev/null || true)"
echo "ls_/bin/sh=$(ls -l /bin/sh 2>/dev/null || true)"
echo "ls_/bin/busybox=$(ls -l /bin/busybox 2>/dev/null || true)"
echo "which_busybox=$(command -v busybox 2>/dev/null || true)"
echo "test_builtin=$(test 1 -eq 1 && echo OK || echo KO)"
echo "bracket_cmd=$(command -v '[' 2>/dev/null || true)"
register: shinfo
- name: Lire version DSM (best effort)
ansible.builtin.shell: |
if test -f /etc.defaults/VERSION; then
cat /etc.defaults/VERSION
elif test -f /etc/VERSION; then
cat /etc/VERSION
else
echo "VERSION_FILE_NOT_FOUND"
fi
args:
executable: /bin/bash
register: dsm_version
changed_when: false
- debug:
var: shinfo.stdout_lines
- name: Afficher version DSM
ansible.builtin.debug:
var: dsm_version.stdout_lines
- debug:
var: shinfo.stderr_lines
# ------------------------------------------------------------
# 1) Découvrir l'outil de MAJ existant
# ------------------------------------------------------------
- name: Chercher des binaires connus (synoupgrade/synoautoupdate/...)
ansible.builtin.shell: |
set +e
candidates="
synoupgrade
synoautoupdate
synoautoupdate2
synoupgrade2
"
echo "== command -v =="
for c in $candidates; do
p="$(command -v "$c" 2>/dev/null)"
if [ -n "$p" ]; then
echo "$c=$p"
fi
done
echo "== common paths =="
for p in \
/usr/syno/sbin/synoupgrade \
/usr/syno/sbin/synoautoupdate \
/usr/syno/bin/synoautoupdate \
/usr/sbin/synoautoupdate \
/usr/syno/sbin/synoupgrade2 \
/usr/syno/sbin/synoautoupdate2
do
if [ -x "$p" ]; then
echo "FOUND=$p"
fi
done
echo "== find (limited) =="
# petit find limité pour éviter de tourner 3h
for root in /usr/syno /usr/sbin /usr/bin /bin /sbin; do
if [ -d "$root" ]; then
find "$root" -maxdepth 3 -type f \( -name "syno*update*" -o -name "syno*upgrade*" \) 2>/dev/null | head -n 50
fi
done
exit 0
args:
executable: /bin/bash
register: discover
changed_when: false
- name: Afficher découverte
ansible.builtin.debug:
var: discover.stdout_lines
- name: Choisir un binaire (priorité: synoupgrade puis synoautoupdate)
ansible.builtin.shell: |
set +e
pick=""
if command -v synoupgrade >/dev/null 2>&1; then
pick="$(command -v synoupgrade)"
elif [ -x /usr/syno/sbin/synoupgrade ]; then
pick="/usr/syno/sbin/synoupgrade"
elif command -v synoautoupdate >/dev/null 2>&1; then
pick="$(command -v synoautoupdate)"
elif [ -x /usr/syno/sbin/synoautoupdate ]; then
pick="/usr/syno/sbin/synoautoupdate"
fi
if [ -z "$pick" ]; then
echo "MISSING"
else
echo "$pick"
fi
exit 0
args:
executable: /bin/bash
register: picked
changed_when: false
- name: Enregistrer outil de MAJ
ansible.builtin.set_fact:
upgrade_tool: "{{ picked.stdout | trim }}"
- name: Stop si aucun outil trouvé (message clair)
ansible.builtin.fail:
msg: >-
Aucun outil de mise à jour trouvé via SSH (synoupgrade/synoautoupdate).
Regarde la tâche "Chercher des binaires connus" pour voir ce qui existe.
Si rien n'apparait, on devra rester sur l'API DSM ou faire via interface DSM.
when: upgrade_tool in ["", "MISSING"]
- name: Debug outil choisi
ansible.builtin.debug:
msg: "Outil retenu: {{ upgrade_tool }}"
# ------------------------------------------------------------
# 2) Afficher l'aide (pour savoir quelles options existent)
# ------------------------------------------------------------
- name: Afficher --help de l'outil
ansible.builtin.shell: |
set +e
"{{ upgrade_tool }}" --help 2>&1 | head -n 120
exit 0
args:
executable: /bin/bash
register: tool_help
changed_when: false
- name: Debug help
ansible.builtin.debug:
var: tool_help.stdout_lines
# ------------------------------------------------------------
# 3) Tenter un check/download/start en best effort
# ------------------------------------------------------------
- name: Check MAJ (best effort)
ansible.builtin.shell: |
set +e
T="{{ upgrade_tool }}"
echo "---- TRY: check ----"
"$T" check 2>&1
rc1=$?
echo "---- TRY: --check ----"
"$T" --check 2>&1
rc2=$?
echo "---- TRY: status ----"
"$T" status 2>&1
rc3=$?
echo "---- TRY: --status ----"
"$T" --status 2>&1
rc4=$?
echo "RCs: check=$rc1 --check=$rc2 status=$rc3 --status=$rc4"
exit 0
args:
executable: /bin/bash
register: check_out
changed_when: false
- name: Afficher check
ansible.builtin.debug:
var: check_out.stdout_lines
- name: Heuristique update dispo
ansible.builtin.set_fact:
update_available: >-
{{
(
(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('download') != -1
or (check_out.stdout | lower).find('télécharg') != -1
or (check_out.stdout | lower).find('dispon') != -1
)
}}
- name: Info update dispo
ansible.builtin.debug:
msg: "MAJ dispo (heuristique) = {{ update_available }}"
- name: Télécharger la MAJ (best effort)
ansible.builtin.shell: |
set +e
T="{{ upgrade_tool }}"
echo "---- TRY: download ----"
"$T" download 2>&1
rc1=$?
echo "---- TRY: --download ----"
"$T" --download 2>&1
rc2=$?
echo "---- TRY: download --start ----"
"$T" download --start 2>&1
rc3=$?
echo "RCs: download=$rc1 --download=$rc2 download--start=$rc3"
exit 0
args:
executable: /bin/bash
register: dl_out
changed_when: true
when: update_available | bool
- name: Afficher download
ansible.builtin.debug:
var: dl_out.stdout_lines
when: update_available | bool
- name: Installer (optionnel, best effort)
ansible.builtin.shell: |
set +e
T="{{ upgrade_tool }}"
echo "---- TRY: start ----"
"$T" start 2>&1
rc1=$?
echo "---- TRY: --start ----"
"$T" --start 2>&1
rc2=$?
echo "---- TRY: upgrade ----"
"$T" upgrade 2>&1
rc3=$?
echo "RCs: start=$rc1 --start=$rc2 upgrade=$rc3"
exit 0
args:
executable: /bin/bash
register: install_out
changed_when: true
when:
- update_available | bool
- do_install | bool
- name: Afficher install
ansible.builtin.debug:
var: install_out.stdout_lines
when:
- update_available | bool
- do_install | bool
- name: Reboot NAS (optionnel)
ansible.builtin.shell: |
sudo reboot || reboot
args:
executable: /bin/bash
when:
- update_available | bool
- do_install | bool
- do_reboot | bool