我正在尝试运行以下Chef命令:
# install zombiejs, q (promises), should, coffee-script & mocha
execute "install q and zombiejs" do
cwd "/home/vagrant"
user "vagrant"
action :run
command "npm install -g q zombie should mocha coffee-script"
end
但是它一直失败,因为找不到npm
:
execute [install q and zombiejs](chef-redtail ::默认行205)有错误:Errno :: ENOENT:无此类文件或目录-npm install -gq zombie应该摩卡咖啡脚本
通过vagrant ssh
并手动运行命令登录到vagrant可以正常工作。sudo -i
以同样的原因,通过厨师主菜谱失败,以root身份登录并通过命令运行失败(npm仅在本地为无业游民用户安装,而不是root用户安装:这就是我想要的)。
那么...我该如何指定该Chef execute
块以无业游民的用户身份而不是root用户身份运行?
更新:我认为这总结了我的问题:
(ssh) /vagrant git:backbone ❯ whoami
vagrant
(ssh) /vagrant git:backbone ❯ which npm
/home/vagrant/.local/bin/npm
(ssh) /vagrant git:backbone ❯ echo $PATH
/home/vagrant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
(ssh) /vagrant git:backbone ❯ sudo -H -u vagrant -i echo $PATH
/home/vagrant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
(ssh) /vagrant git:backbone ❯ sudo -H -u vagrant -i which npm
npm not found
通过http://tickets.opscode.com/browse/CHEF-2517
另一个更新:所以我才注意到这种差异:
(ssh) /vagrant git:backbone ❯ sudo -H -u vagrant -i echo $PATH
/home/vagrant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
(ssh) /vagrant git:backbone ❯ sudo -H -u vagrant -i export
HOME=/home/vagrant
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LOGNAME=vagrant
MAIL=/var/mail/vagrant
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
SHELL=/bin/zsh
SSH_AUTH_SOCK=/tmp/ssh-uJUopA4146/agent.4146
SUDO_COMMAND='/bin/zsh -c export'
SUDO_GID=1001
SUDO_UID=1000
SUDO_USER=vagrant
TERM=xterm
USER=vagrant
请注意其中的区别PATH
?导出中没有/home/vagrant/.local/bin
列出目录...为什么第一个echo PATH
随此返回,而第二个echo PATH
没有它返回?这是问题吗?