[chef] Re: Chef bash resource not executing as specified user


Chronological Thread 
  • From: Joseph Reynolds < >
  • To:
  • Subject: [chef] Re: Chef bash resource not executing as specified user
  • Date: Wed, 25 Jan 2012 10:23:26 -0500

Hi Arthur,

The problem is that the normal environment for hubot_user isn't being loaded during the bash resource run. Because the hubot-user is running the npm command, but has the environment of the chef-client-user, it is writing the npm logs to the chef-client-user's home folder, which it doesn't have permissions for.

At least that's what it looks like to me.

Joe 

On Jan 25, 2012, at 9:32 AM, Arthur Kalmenson wrote:

I'm writing a Chef cookbook to install Hubot. In the recipe, I do the following:

bash "install hubot" do
  user hubot_user
  group hubot_group
  cwd install_dir
  code <<-EOH
    tar xzvf hubot-#{node['hubot']['version']}.tar.gz && \
    cd hubot && \
    npm install
  EOH
end


However, when I try to run chef-client on the server installing the cookbook, I'm getting a permission denied writing to the directory of the user that runs chef-client, not the hubot user. For some reason, npm is trying to run under the wrong user, not the user specified in the bash resource.

I am able to run sudo su - hubot -c "npm install /usr/local/hubot/hubot" manually, and this gets the result I want (installs hubot as the hubot user). However, it seems chef-client isn't executing the command as the hubot user. Below you'll find the chef-client execution. Thank you in advance.


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/<chef-client-user>/.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/<chef-client-user>/.npm/log/1.2.0/package.tgz
npm ERR! error installing Error: EACCES, permission denied '/home/<chef-client-user>/.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

--
Arthur Kalmenson




Archive powered by MHonArc 2.6.16.

§