You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在CentOS 7上用Ansible部署JsReport的问题求助

Ansible script for installing jsReport on CentOS 7 fails with multiple errors (nvm/node not recognized, puppeteer installation failure, missing instance)

I'm trying to automate the installation of jsReport on CentOS 7 using Ansible, following the official CentOS installation steps. I've put together an initial script, but it's throwing a bunch of errors at different stages. Even after making adjustments like creating a dedicated system user and adding manual dependency installs, some issues persist—while manual steps work, the script still fails in key places.

Here's a breakdown of the problems I've encountered:

Error Stages

1. Initial Script Execution

Right out the gate, the script hit several issues:

  • Directory already exists errors when trying to set up the jsReport workspace
  • jsreportapp: command not found after running jsreport init
  • node: command not found even after installing nvm and Node.js
  • Puppeteer installation failure during the npm install step for jsReport

2. After Script Adjustments

I updated the script to create a dedicated jsreport system user and explicitly install required system dependencies, but two critical errors remained:

  • node: command not found still popped up in Node-related tasks
  • Puppeteer installation failure persisted

3. Partial Success with Manual Intervention

When I manually installed all required system dependencies on the target server, the script ran without immediate errors—but when it tried to start jsReport as the jsreport user, I got the error: "cannot find installed instance".

My Ansible Script

---
- name: Automate jsReport installation on CentOS 7
  hosts: centos_targets
  become: yes
  tasks:
    - name: Create dedicated jsReport system user
      user:
        name: jsreport
        system: yes
        create_home: yes
        home: /opt/jsreport
        shell: /bin/bash

    - name: Install required system packages for jsReport and Puppeteer
      yum:
        name:
          - gcc-c++
          - make
          - libX11
          - libXext
          - libXtst
          - libXScrnSaver
          - libXdamage
          - libXfixes
          - libXrandr
          - libXcursor
          - libXcomposite
          - libXrender
          - cups-libs
          - libdrm
          - mesa-libgbm
          - atk
          - at-spi2-atk
          - gtk3
          - wget
        state: present
        update_cache: yes

    - name: Install nvm for jsReport user
      shell: |
        curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
      args:
        executable: /bin/bash
        chdir: /opt/jsreport
        creates: /opt/jsreport/.nvm
      become_user: jsreport

    - name: Install Node.js 18 LTS via nvm
      shell: |
        source ~/.nvm/nvm.sh && nvm install 18 && nvm alias default 18
      args:
        executable: /bin/bash
        chdir: /opt/jsreport
      become_user: jsreport

    - name: Install jsReport CLI and initialize instance
      shell: |
        npm install -g jsreport-cli
        jsreport init jsreportapp
        cd jsreportapp
        npm install
      args:
        executable: /bin/bash
        chdir: /opt/jsreport
      become_user: jsreport

    - name: Start jsReport service
      shell: |
        jsreport start
      args:
        executable: /bin/bash
        chdir: /opt/jsreport/jsreportapp
      become_user: jsreport

What I Need Help With

I'm stuck on three main points:

  1. How can I ensure the nvm/Node.js environment is properly loaded and recognized in Ansible shell tasks? It seems like the environment variables aren't persisting between tasks.
  2. What's causing the Puppeteer installation failure, and how can I fix it via Ansible? I've installed the system dependencies mentioned in the docs, but it still fails.
  3. Why does jsreport start throw a "cannot find installed instance" error when run via Ansible, even though it works when I run the command manually as the jsreport user?

Any guidance or fixes for these issues would be greatly appreciated!

内容的提问来源于stack exchange,提问作者tryingHard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 05:19:31