Permission Denied when uploading solo.rb
I am testing my chef deployments with vagrant, and started out deploying with the vagrant user. I have tried to abstract away the user from vagrant, and am now trying to use a different user, creating when I bootstrap the box.
When I run fix node:123.123.123.123 using the vagrant user, everything runs perfectly fine, but when I run it using the chef user, (who owns the /etc/chef directory, and can sudo without a password) it fails with the error:
Fatal error: put() encountered an exception while uploading '<StringIO.StringIO instance at 0x10fecc200>'
Underlying exception:
Permission denied
This exception is thrown around line 94 of solo.py:
upload_template(os.path.join(BASEDIR, 'solo.rb'), '/etc/chef/',
context=data, use_sudo=True, backup=False, mode=0400)
Why does this happen even though the chef user has the correct permissions?
The problem is caused by upload_template having two phases:
- using
put()to upload the file to the user's home directory - using
sudoto move the file to its final destination dir at/etc/chef
Because you are using the chef user, which doesn't have a home directory, that step is failing. So the solution is to always use "real" system users, that is users which have a home directory.
On LittleChef's side, what we can do is catch that error and output a proper error message, as "Permission denied" is totally useless for a user encountering the problem.
Ah, that makes sense. I don't have the means to test that yet, as my computer blew up about an hour after I opened the issue, but I'll try creating a user with a home and post results when I get a chance.
Tried out creating a new user with a home directory, and it worked perfectly. Thanks!
I would recommend a more descriptive error message like you mentioned.
Committed a partial fix (Ugly error still appears), and filed a bug in fabric (fabric/fabric#629), needed to be able to fix it more nicely on our side.
Will leave this open until then
I'm still getting an error here, but not Permissions. I get the following:
$ fix --verbose node:10.14.209.171 deploy_chef
Are you sure you want to install Chef 0.10 at the node 10.14.209.171, using "precise" packages? [Y/n]
Setting up Opscode repository...
Installing Chef Solo
Fatal error: put() encountered an exception while uploading '<StringIO.StringIO instance at 0x108eef950>'
Underlying exception:
unsupported operand type(s) for &: 'NoneType' and 'int'
Aborting.
Fatal error: Failed to upload '/etc/chef/solo.rb'
This can happen when the deployment user does not have a home directory, which is needed as a temporary location
Aborting.
Disconnecting from 10.14.209.171... done.
I have tried both directly as root and as a real user chef with sudo permissions. I can see that the template file exists in the home directory with a file name of a long hash, but it appears to fail on moving it to /etc/chef/solo.rb
Looks like I overlooked #151
Thanks @gondoi , I hope the LittleChef 1.5.0 release today fixes your issue.