所以问题基本上很简单 - npm install 在我通过 Ansible 的流浪汉设置上不起作用,但当我从控制台运行时,效果很好
案例1(我有一些带台词的剧本:
...
- name: install frontend libs
npm: path=/vagrant/frontend/bem
...
当我运行流浪条款时,当涉及到这一点时,它会崩溃得超级糟糕:
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 实现相同的行为?
你用哪个用户运行这个 npm 命令?您可能希望以其他用户身份运行它:
- name: install frontend libs
npm: path=/vagrant/frontend/bem
sudo: yes
sudo_user: someuser