在CentOS 7上用Ansible部署JsReport的问题求助
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 foundafter runningjsreport initnode: command not foundeven after installing nvm and Node.js- Puppeteer installation failure during the
npm installstep 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 foundstill 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:
- 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.
- 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.
- Why does
jsreport startthrow a "cannot find installed instance" error when run via Ansible, even though it works when I run the command manually as thejsreportuser?
Any guidance or fixes for these issues would be greatly appreciated!
内容的提问来源于stack exchange,提问作者tryingHard

