Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm facing a weird problem when executing chef-solo commands on Ubuntu 10.04.

If I execute this (as root):

# chef-solo -c /opt/mycorp/mycorp-chef-code/config/solo.rb -j /opt/mycorp/mycorp-chef-code/config/run_mycorp-config.json
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: Setting the run_list to ["recipe[mycorp-config]"] from JSON
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: Starting Chef Run (Version 0.9.12)
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: Chef Run complete in 0.47172 seconds
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: cleaning the checksum cache
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: Running report handlers
[Tue, 16 Nov 2010 15:28:49 +0100] INFO: Report handlers complete

However If I execute the same exact command whith sudo (either as root or as a sudoer) I get this:

# sudo chef-solo -c /opt/mycorp/mycorp-chef-code/config/solo.rb -j /opt/mycorp/mycorp-chef-code/config/run_mycorp-config.json
[Tue, 16 Nov 2010 15:28:37 +0100] INFO: Setting the run_list to ["recipe[mycorp-config]"] from JSON
[Tue, 16 Nov 2010 15:28:37 +0100] INFO: Starting Chef Run (Version 0.9.12)
[Tue, 16 Nov 2010 15:28:38 +0100] ERROR: Running exception handlers
[Tue, 16 Nov 2010 15:28:38 +0100] ERROR: Exception handlers complete
/opt/mycorp/mycorp-chef-code/chef-repo/cookbooks/tomcat6/attributes/default.rb:45:in `from_file': undefined method `[]' for nil:NilClass (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/node.rb:578:in `load_attributes'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/node.rb:576:in `each'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/node.rb:576:in `load_attributes'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/node.rb:575:in `each'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/node.rb:575:in `load_attributes'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/run_context.rb:74:in `load'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/run_context.rb:55:in `initialize'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/client.rb:155:in `new'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/client.rb:155:in `run'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/application/solo.rb:190:in `run_application'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/application/solo.rb:181:in `loop'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/application/solo.rb:181:in `run_application'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/../lib/chef/application.rb:62:in `run'
    from /usr/lib/ruby/gems/1.8/gems/chef-0.9.12/bin/chef-solo:25
    from /usr/bin/chef-solo:19:in `load'
    from /usr/bin/chef-solo:19

Any idea? I'm definitely lost on this, why would using sudo cause a problem, even if the user issuing the command is root.

Thanks in advance.

share|improve this question
    
Diving into "tomcat6" recipe showed that it needed java to work. It was not in the default PATH used by sudo and that was why it failed. Adding a customised "Defaults secure_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/local/bin:/op‌​t/my_java/" to sudoers file did the trick. –  Francisco Nov 17 '10 at 11:32

1 Answer 1

up vote 2 down vote accepted

It's a bit strange but Sudo does change environment variables so maybe chef-solo is thrown off by that.

As root run: env and then run sudo env

You'll see that the variables are completely different.

Other toughts

Here is some info form the man page:

If sudo is run by root and the SUDO_USER environment variable is set, sudo will use this value to determine who the actual user is. This can be used by a user to log commands through sudo even when a root shell has been invoked. It also allows the -e flag to remain useful even when being run via a sudo-run script or program. Note however, that the sudoers lookup is still done for root, not the user specified by SUDO_USER.

Is your SUDO_USER set before you run sudo? Check with echo $SUDO_USER.

The sudoers table still gets consulted even if you are root so check your sudoers file.

share|improve this answer
    
Thanks for your answer. Actually, it was related to $PATH variable being different inside the sudo environment. –  Francisco Nov 17 '10 at 11:35
    
The actual problem is that the default sudoers file in Ubuntu does "env_reset". Best bet is to use chef to replace the broken default configuration. Its not more secure :). –  jtimberman Dec 3 '10 at 6:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.