--- - name: Synology DSM - Télécharger (et optionnellement installer) une mise à jour via SSH hosts: synology gather_facts: false vars: do_install: false # true si tu veux lancer l'install après download do_reboot: false # true si tu veux reboot après install download_timeout: 7200 tasks: # ------------------------------------------------------------ # 0) Version DSM # ------------------------------------------------------------ - name: Lire la version DSM (DSM6/DSM7) 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 - name: Afficher version DSM ansible.builtin.debug: var: dsm_version.stdout_lines # ------------------------------------------------------------ # 1) Trouver synoupgrade # ------------------------------------------------------------ - name: Détecter synoupgrade ansible.builtin.shell: | if command -v synoupgrade >/dev/null 2>&1; then command -v synoupgrade exit 0 fi for p in \ /usr/syno/sbin/synoupgrade \ /usr/sbin/synoupgrade \ /sbin/synoupgrade \ /bin/synoupgrade \ /usr/bin/synoupgrade do if test -x "$p"; then echo "$p" exit 0 fi done echo "MISSING" exit 0 args: executable: /bin/bash register: synoupgrade_path changed_when: false - name: Enregistrer le binaire synoupgrade ansible.builtin.set_fact: synoupgrade_bin: "{{ synoupgrade_path.stdout | trim }}" - name: Fail si synoupgrade introuvable ansible.builtin.fail: msg: "synoupgrade introuvable sur ce NAS. stdout='{{ synoupgrade_path.stdout | trim }}'" when: synoupgrade_bin in ["", "MISSING"] - name: Debug synoupgrade ansible.builtin.debug: msg: "synoupgrade détecté: {{ synoupgrade_bin }}" # ------------------------------------------------------------ # 2) Check si une MAJ est dispo (best effort) # ------------------------------------------------------------ - name: Check mise à jour disponible (best effort) ansible.builtin.shell: | set +e SYNO="{{ synoupgrade_bin }}" echo "---- HELP ----" "$SYNO" --help 2>/dev/null | head -n 80 echo "---- TRY: check ----" "$SYNO" check 2>&1 rc1=$? echo "---- TRY: --check ----" "$SYNO" --check 2>&1 rc2=$? echo "---- TRY: --status ----" "$SYNO" --status 2>&1 rc3=$? echo "RCs: check=$rc1 --check=$rc2 --status=$rc3" exit 0 args: executable: /bin/bash register: check_out changed_when: false - name: Afficher résultat du check ansible.builtin.debug: var: check_out.stdout_lines - name: Déterminer si une mise à jour semble dispo (heuristique) 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 dispo maj ansible.builtin.debug: msg: "MAJ dispo (heuristique) = {{ update_available }}" # ------------------------------------------------------------ # 3) Télécharger la MAJ (si dispo) # ------------------------------------------------------------ - name: Télécharger la mise à jour DSM (best effort) ansible.builtin.shell: | set +e SYNO="{{ synoupgrade_bin }}" echo "---- TRY: download ----" "$SYNO" download 2>&1 rc1=$? echo "---- TRY: --download ----" "$SYNO" --download 2>&1 rc2=$? echo "---- TRY: download --start ----" "$SYNO" 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 sortie download ansible.builtin.debug: var: dl_out.stdout_lines when: update_available | bool - name: Stop si aucune MAJ détectée ansible.builtin.debug: msg: "Aucune mise à jour détectée (heuristique). Rien à télécharger." when: not (update_available | bool) # ------------------------------------------------------------ # 4) Optionnel : installer # ------------------------------------------------------------ - name: Installer DSM (optionnel) ansible.builtin.shell: | set +e SYNO="{{ synoupgrade_bin }}" echo "---- TRY: start ----" "$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: executable: /bin/bash register: install_out changed_when: true when: - update_available | bool - do_install | bool - name: Afficher sortie install ansible.builtin.debug: var: install_out.stdout_lines when: - update_available | bool - do_install | bool # ------------------------------------------------------------ # 5) Optionnel : reboot # ------------------------------------------------------------ - name: Reboot NAS (optionnel) ansible.builtin.shell: | sudo reboot || reboot args: executable: /bin/bash when: - update_available | bool - do_install | bool - do_reboot | bool