Impossible to create /node/modules directory for TypeScript or Javascript code and modules

a_m
Mon, 09 Feb 2026 11:21:38 +0000
Get Help

hello,
I need help for my symfony 6.4 project.
my ansible version by pipx manager informatic linux programm is : 2.20.2
it’s impossible to execute my playbook correctly , see this :

---
- hosts: servers
  vars_files:
    - ./ansible/group_vars/all/vault.yml
  become: yes
  vars:
    symfony_root: /var/www/X
    local_project_root: "/home/alexandre/Documents/X"
    nvm_dir: "/usr/local/nvm"
    nvm_version: "v0.40.3"
    node_version: "24.7.0"
    composer_path: "/usr/local/bin/composer"  # Chemin fixe car vous l'avez confirmé

  tasks:
    - debug:
        msg: "Ansible version: {{ ansible_version.full }}"

    # === 1. Vérification de Composer (déjà installé selon vous) ===
    - name: Vérifier que Composer est accessible
      command: "{{ composer_path }} --version --no-interaction"
      register: composer_check
      ignore_errors: yes
      changed_when: false
      environment:
        COMPOSER_ALLOW_SUPERUSER: "1"  # Autorise l'exécution en root
        COMPOSER_NO_INTERACTION: "1"   # Désactive les prompts

    - name: Échouer si Composer n'est pas disponible
      fail:
        msg: "Composer n'est pas installé dans {{ composer_path }}. Veuillez l'installer manuellement."
      when: composer_check.rc != 0

    # === 2. Installation de NVM et Node.js ===
    - name: Créer un répertoire global pour NVM
      file:
        path: "{{ nvm_dir }}"
        state: directory
        owner: root
        group: root
        mode: '0755'

    - name: Télécharger et installer nvm globalement
      shell: |
        curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/{{ nvm_version }}/install.sh | bash
      args:
        creates: "{{ nvm_dir }}/nvm.sh"
      environment:
        NVM_DIR: "{{ nvm_dir }}"
        PROFILE: "/dev/null"

    - name: Installer Node.js avec NVM
      shell: |
        export NVM_DIR="{{ nvm_dir }}"
        [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
        nvm install {{ node_version }}
        nvm use {{ node_version }}
      environment:
        NVM_DIR: "{{ nvm_dir }}"
        PATH: "{{ nvm_dir }}/versions/node/v{{ node_version }}/bin:{{ ansible_env.PATH }}"

    # === 3. Préparation du projet ===
    - name: Créer le répertoire du projet avec les bonnes permissions
      file:
        path: "{{ symfony_root }}"
        state: directory
        owner: www-data
        group: www-data
        mode: '0755'

    - name: Créer les répertoires nécessaires pour Symfony
      block:
        - name: Créer var/log
          file:
            path: "{{ symfony_root }}/var/log"
            state: directory
            owner: www-data
            group: www-data
            mode: '0775'

        - name: Créer var/cache
          file:
            path: "{{ symfony_root }}/var/cache"
            state: directory
            owner: www-data
            group: www-data
            mode: '0775'

        - name: Créer .npm pour www-data
          file:
            path: "/home/www-data/.npm"
            state: directory
            owner: www-data
            group: www-data
            mode: '0755'

    # === 4. Synchronisation des fichiers ===
    - name: Synchroniser les fichiers du projet
      ansible.posix.synchronize:
        src: "{{ local_project_root }}/"
        dest: "{{ symfony_root }}"
        delete: yes
        mode: push
        compress: true
        rsync_opts:
          - "--iconv=utf-8,utf-8"
          - "--exclude=.git"
          - "--exclude=*.sh"
          - "--exclude=/vendor"
          - "--exclude=/ansible"
          - "--exclude=/node_modules"
          - "--exclude=var/cache/*"
          - "--exclude=var/log/*"
          - "--exclude=.env.local"
          - "--exclude=package-lock.json"
      become: no
      delegate_to: localhost

    # === 5. Gestion des permissions ===
    - name: Corriger les permissions du projet
      file:
        path: "{{ symfony_root }}"
        state: directory
        owner: www-data
        group: www-data
        recurse: yes

    # === 6. Gestion de node_modules ===
    - name: Supprimer package-lock.json s'il existe
      file:
        path: "{{ symfony_root }}/package-lock.json"
        state: absent

    - name: Créer un nouveau package-lock.json
      command: npm install --package-lock-only
      args:
        chdir: "{{ symfony_root }}"
      become: yes
      become_user: www-data
      environment:
        NVM_DIR: "{{ nvm_dir }}"
        PATH: "{{ nvm_dir }}/versions/node/v{{ node_version }}/bin:{{ ansible_env.PATH }}"
        HOME: "/home/www-data"
        npm_config_cache: "/home/www-data/.npm"

    - name: Mettre à jour les paquets npm si node_modules existe
      command: npm update
      args:
        chdir: "{{ symfony_root }}"
      become: yes
      become_user: www-data
      environment:
        NVM_DIR: "{{ nvm_dir }}"
        PATH: "{{ nvm_dir }}/versions/node/v{{ node_version }}/bin:{{ ansible_env.PATH }}"
        HOME: "/home/www-data"
        npm_config_cache: "/home/www-data/.npm"
      when: lookup('fileglob', symfony_root + '/node_modules/*', wantlist=True) | length > 0

          # === Correction des versions Symfony ===
    # - name: Corriger les versions Symfony dans composer.json
    #   replace:
    #     path: "{{ symfony_root }}/composer.json"
    #     regexp: '"symfony/(http-client|process|security-bundle|validator)": "[^"]*"'
    #     replace: '"symfony/\1": "^6.4"'
    #   become: yes
    #   become_user: www-data

    # - name: Supprimer composer.lock pour permettre la mise à jour
    #   file:
    #     path: "{{ symfony_root }}/composer.lock"
    #     state: absent
    #   become: yes
    #   become_user: www-data


    # === 7. Gestion de Symfony (avec gestion d'erreurs) ===
    - name: Gérer les dépendances Symfony
      block:
        - name: Vérifier si symfony/runtime est installé
          command: "{{ composer_path }} show symfony/runtime"
          args:
            chdir: "{{ symfony_root }}"
          register: runtime_check
          ignore_errors: yes
          changed_when: false
          become: yes
          become_user: www-data
          environment:
            COMPOSER_HOME: "/home/www-data/.composer"
            PATH: "/usr/local/bin:{{ ansible_env.PATH }}"

        - name: Installer symfony/runtime si nécessaire
          command: "{{ composer_path }} require symfony/runtime --no-interaction --optimize-autoloader"
          args:
            chdir: "{{ symfony_root }}"
          become: yes
          become_user: www-data
          when: runtime_check.rc is defined and runtime_check.rc != 0
          environment:
            COMPOSER_HOME: "/home/www-data/.composer"
            COMPOSER_NO_INTERACTION: "1"
            PATH: "/usr/local/bin:{{ ansible_env.PATH }}"



        - name: Installer les dépendances Composer
          command: "{{ composer_path }} install --optimize-autoloader --no-interaction"
          args:
            chdir: "{{ symfony_root }}"
          become: yes
          become_user: www-data
          environment:
             COMPOSER_HOME: "/home/www-data/.composer"
             COMPOSER_ALLOW_SUPERUSER: "1"
             COMPOSER_NO_INTERACTION: "1"
             APP_ENV: dev
             PATH: "/usr/local/bin:{{ ansible_env.PATH }}"

        - name: Nettoyer le cache Symfony
          command: "php bin/console cache:clear --env=dev"
          args:
            chdir: "{{ symfony_root }}"
          become: yes
          become_user: www-data
          environment:
            APP_ENV: dev
            PATH: "/usr/local/bin:{{ ansible_env.PATH }}"


      rescue:
        - name: Afficher l'erreur détaillée
          debug:
            var: ansible_failed_result

        - name: Créer le fichier de log si absent
          file:
            path: "{{ symfony_root }}/var/log/prod.log"
            state: touch
            owner: www-data
            group: www-data
            mode: '0664'

        - name: Vérifier les logs Symfony (si le fichier existe)
          command: "tail -n 20 {{ symfony_root }}/var/log/prod.log"
          register: symfony_logs
          ignore_errors: yes
          become: yes
          become_user: www-data

        - name: Afficher les logs
          debug:
            var: symfony_logs.stdout_lines
          when: symfony_logs.stdout is defined and symfony_logs.stdout | length > 0

        - name: Redémarrer PHP-FPM
          service:
            name: "php8.3-fpm"
            state: restarted
          when: ansible_os_family == 'Debian'
          become: yes

i would like to have more verbosity in my feedback, but i don’t know exactly how ?can you help me for this first detail

the feedback is this/that (excuses me for my english) :

alexandre@alexandre-Matebook:~/Documents/X$ ansible-playbook -i ./ansible/inventory.ini  ./ansible/playbookQuatre.yml

PLAY [servers] **********************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************
ok: [ubuntu]

TASK [debug] ************************************************************************************************************************************************************
ok: [ubuntu] => {
    "msg": "Ansible version: 2.20.2"
}

TASK [Vérifier que Composer est accessible] *****************************************************************************************************************************
ok: [ubuntu]

TASK [Échouer si Composer n'est pas disponible] *************************************************************************************************************************
skipping: [ubuntu]

TASK [Créer un répertoire global pour NVM] ******************************************************************************************************************************
ok: [ubuntu]

TASK [Télécharger et installer nvm globalement] *************************************************************************************************************************
ok: [ubuntu]

TASK [Installer Node.js avec NVM] ***************************************************************************************************************************************
changed: [ubuntu]

TASK [Créer le répertoire du projet avec les bonnes permissions] ********************************************************************************************************
changed: [ubuntu]

TASK [Créer var/log] ****************************************************************************************************************************************************
changed: [ubuntu]

TASK [Créer var/cache] **************************************************************************************************************************************************
changed: [ubuntu]

TASK [Créer .npm pour www-data] *****************************************************************************************************************************************
ok: [ubuntu]

TASK [Synchroniser les fichiers du projet] ******************************************************************************************************************************
changed: [ubuntu -> localhost]

TASK [Corriger les permissions du projet] *******************************************************************************************************************************
changed: [ubuntu]

TASK [Supprimer package-lock.json s'il existe] **************************************************************************************************************************
changed: [ubuntu]

TASK [Créer un nouveau package-lock.json] *******************************************************************************************************************************
changed: [ubuntu]

TASK [Mettre à jour les paquets npm si node_modules existe] *************************************************************************************************************
[WARNING]: Unable to find '/var/www/X/node_modules' in expected paths (use -vvvvv to see paths)
skipping: [ubuntu]

TASK [Vérifier si symfony/runtime est installé] *************************************************************************************************************************
ok: [ubuntu]

TASK [Installer symfony/runtime si nécessaire] **************************************************************************************************************************
skipping: [ubuntu]

TASK [Installer les dépendances Composer] *******************************************************************************************************************************
changed: [ubuntu]

TASK [Nettoyer le cache Symfony] ****************************************************************************************************************************************
changed: [ubuntu]

PLAY RECAP **************************************************************************************************************************************************************
ubuntu                     : ok=17   changed=10   unreachable=0    failed=0    skipped=3    rescued=0    ignored=0

alexandre@alexandre-Matebook:~/Documents/X$

could you help me ?

6 posts - 2 participants