所以问题基本上很简单 - npm install不能通过Ansible在我的Vagrant设置上运行,但是当我从控制台运行它时效果非常好
案例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实现相同的行为?
答案 0 :(得分:0)
您使用哪个用户运行此npm命令?您可能希望以另一个用户身份运行它:
- name: install frontend libs
npm: path=/vagrant/frontend/bem
sudo: yes
sudo_user: someuser