Sudo and chef-solo problems

chefchef-solosudoubuntu-10.04

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.

Best Answer

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.

Related Topic