node.js - npm 安装和 Vagrant/Ansible 文件夹 chmod 问题

标签 node.js npm vagrant ansible

所以问题基本上很简单 - npm install 无法通过 Ansible 在我的 Vagrant 设置上运行,但是当我从控制台运行它时效果很好

案例 1) 我有一些带有线条的剧本:

... 
- name: install frontend libs
  npm: path=/vagrant/frontend/bem
...

当我运行 vagrant provision 时,当谈到这一点时,它崩溃得非常糟糕:

TASK: [nodejs | install frontend libs] **************************************** 
failed: [default] => {"cmd": "/usr/bin/npm install", "failed": true, "rc": 50}
stderr: npm http GET https://registry.npmjs.org/bem/0.8.1
npm http GET https://registry.npmjs.org/bem-tools-autoprefixer/0.0.3
... 
lots of similar lines here
...
npm ERR! Error: EPERM, chown '/vagrant/frontend/bem/node_modules/enb-bembundle/package.json'
npm ERR!  { [Error: EPERM, chown '/vagrant/frontend/bem/node_modules/enb-bembundle/package.json']
npm ERR!   errno: 50,
npm ERR!   code: 'EPERM',
npm ERR!   path: '/vagrant/frontend/bem/node_modules/enb-bembundle/package.json',
npm ERR!   fstream_finish_call: 'chown',
npm ERR!   fstream_type: 'File',
npm ERR!   fstream_path: '/vagrant/frontend/bem/node_modules/enb-bembundle/package.json',
npm ERR!   fstream_class: 'FileWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/lib/nodejs/fstream/lib/writer.js:305:19',
npm ERR!      '/usr/lib/nodejs/graceful-fs/polyfills.js:133:7',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
... 
lots of similar lines here
...
npm ERR! System Linux 3.13.0-24-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! cwd /vagrant/frontend/bem
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /vagrant/frontend/bem/node_modules/bem/package.json
npm ERR! fstream_path /vagrant/frontend/bem/node_modules/bem/package.json
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! fstream_finish_call chown
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, chown '/vagrant/frontend/bem/node_modules/bem/package.json'
npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/writer.js:305:19
npm ERR! fstream_stack /usr/lib/nodejs/graceful-fs/polyfills.js:133:7
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/frontend/bem/npm-debug.log
npm ERR! not ok code 0

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/Users/idmultiship/playbook-web.retry

default                    : ok=24   changed=13   unreachable=0    failed=1   

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

当我在 node_modules 文件夹中查找权限时,它具有 drwxr-xr-x 权限。

案例 2) 当我转到我的 VM 并手动运行 npm install 时,它工作正常,node_modules 权限为 drwxrwxr-x

那么问题来了——我怎样才能通过 ansible 实现相同的行为?

最佳答案

你用哪个用户运行这个 npm 命令?您可能希望以其他用户身份运行它:

- name: install frontend libs
  npm: path=/vagrant/frontend/bem
  sudo: yes
  sudo_user: someuser

关于node.js - npm 安装和 Vagrant/Ansible 文件夹 chmod 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27505100/

相关文章:

docker - Puppet 中的 SSL 证书验证失败

node.js - 如何在nodejs中读取不完整的文件并等待新数据

javascript - 在没有摩卡超时的情况下测试 socket.on ('data' ) 回调

node.js - Azure 部署失败 - 容器未响应端口 : 8080, 上的 HTTP ping,站点启动失败

javascript - 如何在一个 gulp 任务中运行多个操作?

ubuntu - 默认同步文件夹在 vagrant up 后不起作用,但在 vagrant 重新加载后起作用

node.js - 使用 Electron 选择桌面屏幕的区域

node.js - 在 Jenkins 中运行时,NPM 测试神秘地卡住了

symfony - webpack:无法读取未定义的属性 'match'

ruby - Vagrant 与 librarian-chef 通过 ruby​​_build & rbenv 安装 ruby