【问题标题】:npm install and Vagrant/Ansible folder chmod issuenpm install 和 Vagrant/Ansible 文件夹 chmod 问题
【发布时间】:2014-12-16 12:52:13
【问题描述】:

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

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

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

当我运行 vagrant provision 时,当涉及到这一点时,它会崩溃 superbad:

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) 当我转到我的虚拟机并手动运行 npm install 时,它工作正常,并且 node_modules 权限是 drwxrwxr-x

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

【问题讨论】:

  • 看起来是 umask 的问题。

标签: node.js npm vagrant ansible


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-05-26
    • 2015-10-05
    • 2021-08-31
    • 1970-01-01
    • 2016-10-29
    • 2017-11-12
    • 1970-01-01
    • 2022-01-15
    • 2016-11-23
    相关资源
    最近更新 更多