我正在写厨师食谱来安装Hubot。在食谱中,我执行以下操作:
bash "install hubot" do
user hubot_user
group hubot_group
cwd install_dir
code <<-EOH
wget https://github.com/downloads/github/hubot/hubot-#{node['hubot']['version']}.tar.gz && \
tar xzvf hubot-#{node['hubot']['version']}.tar.gz && \
cd hubot && \
npm install
EOH
end
但是,当我尝试在安装本食谱的服务器上运行Chef-client时,我获得了拒绝写入运行Chef-client用户(而不是hubot用户)用户目录的权限。由于某种原因,npm
试图在错误的用户下运行,而不是在bash资源中指定的用户下运行。
我能够sudo su - hubot -c "npm install /usr/local/hubot/hubot"
手动运行,这会得到我想要的结果(以hubot用户身份安装hubot)。但是,chef-client似乎没有以hubot用户身份执行命令。在下面,您将找到Chef-Client执行。先感谢您。
Saving to: `hubot-2.1.0.tar.gz'
0K ...... 100% 563K=0.01s
2012-01-23 12:32:55 (563 KB/s) - `hubot-2.1.0.tar.gz' saved [7115/7115]
npm ERR! Could not create /home/<user-chef-client-uses>/.npm/log/1.2.0/package.tgz
npm ERR! Failed creating the tarball.
npm ERR! couldn't pack /tmp/npm-1327339976597/1327339976597-0.13104878342710435/contents/package to /home/<user-chef-client-uses>/.npm/log/1.2.0/package.tgz
npm ERR! error installing hubot@2.1.0 Error: EACCES, permission denied '/home/<user-chef-client-uses>/.npm/log'
...
npm not ok
---- End output of "bash" "/tmp/chef-script20120123-25024-u9nps2-0" ----
Ran "bash" "/tmp/chef-script20120123-25024-u9nps2-0" returned 1