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.
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.
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:
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.
On Wednesday, January 25, 2012 at 7:23 AM, Joseph Reynolds wrote:
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
Setting the user in a script or execute resource will change the UID that the process runs as, but this is not the same as logging in as that user at the console. In particular, profile and rc scripts will not be sourced as they would during a normal login. The man page for bash explains this under the "Invocation" section:
Joseph,
Yeah, it looks the same to me as well. But how would I work around that?
Daniel,
That makes sense, but is there a way to source it so it runs as if it's
logged in?
Thank you all for your help.
--
Arthur Kalmenson
On Wed, Jan 25, 2012 at 11:18 AM, Daniel DeLeo dan@kallistec.com wrote:
On Wednesday, January 25, 2012 at 7:23 AM, Joseph Reynolds wrote:
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
Setting the user in a script or execute resource will change the UID that
the process runs as, but this is not the same as logging in as that user at
the console. In particular, profile and rc scripts will not be sourced as
they would during a normal login. The man page for bash explains this under
the "Invocation" section:
Daniel,
Thanks, setting the "environment" attribute worked. I've voted and watched
that issue, so we'll see where it goes.
Seth,
Thanks for that Gist, it gave me good ideas on how to implement it, and it
helped a lot. Any chance of integrating a similar cookbook with the current
opscode cookbooks? I guess I could tweak mine to be similar and make a pull
request for that..
On Wednesday, January 25, 2012 at 8:42 AM, Daniel DeLeo wrote:
On Wednesday, January 25, 2012 at 8:32 AM, Arthur Kalmenson wrote:
Leonardo,
Yes, running as sudo
Joseph,
Yeah, it looks the same to me as well. But how would I work around that?
Daniel,
That makes sense, but is there a way to source it so it runs as if it's
logged in?
You could try adding the -l flag to the bash resource, and setting the
HOME environment variable using the environment attribute of the bash
resource.
I created an improvement request for this: http://tickets.opscode.com/browse/CHEF-2288 There are some workarounds
posted.