matschaffer / knife-solo

DEPRECATED: Please consider using https://knife-zero.github.io/, ansible, or visit https://www.chef.io/ for other ideas
MIT License
787 stars 213 forks source link

Command line arguments passed to knife solo silently clobbered if they contain "sudo" chars #446

Open shyouhei opened 9 years ago

shyouhei commented 9 years ago

I have a recipe called "sudoers" and want to run this via knife solo's "-o" option.

[shyouhei@kickhost chef-repos]$ mkdir -p recipes
[shyouhei@kickhost chef-repos]$ echo 'file "/etc/sudoers" do action :touch end' >> recipes/sudoers.rb
[shyouhei@kickhost chef-repos]$ knife solo cook target -o 'recipes[sudoers]'
Running Chef on target...
Checking Chef version...
Generating node config 'nodes/target.json'...
Installing Berkshelf cookbooks to 'cookbooks'...
Resolving cookbook dependencies...
Uploading the kitchen...
WARNING: Local cookbook_path '/home/shyouhei/chef-repos/cookbooks' does not exist
Generating solo config...
Running Chef...
/opt/chef/embedded/apps/chef/lib/chef/run_list/run_list_item.rb:59:in `initialize': Unable to create Chef::RunList::RunListItem from String:"recipes[sudo": must be recipe[] or role[] (ArgumentError)
        from /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:147:in `new'
        from /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:147:in `block (2 levels) in <class:Solo>'
        from /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:146:in `map'
        from /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:146:in `block in <class:Solo>'
        from /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-cli-1.5.0/lib/mixlib/cli.rb:236:in `call'
        from /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-cli-1.5.0/lib/mixlib/cli.rb:236:in `block (3 levels) in opt_parser'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1390:in `call'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1390:in `block in parse_in_order'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1346:in `catch'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1346:in `parse_in_order'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1340:in `order!'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1432:in `permute!'
        from /opt/chef/embedded/lib/ruby/2.1.0/optparse.rb:1454:in `parse!'
        from /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/mixlib-cli-1.5.0/lib/mixlib/cli.rb:192:in `parse_options'
        from /opt/chef/embedded/apps/chef/lib/chef/application.rb:84:in `configure_chef'
        from /opt/chef/embedded/apps/chef/lib/chef/application.rb:47:in `reconfigure'
        from /opt/chef/embedded/apps/chef/lib/chef/application/solo.rb:180:in `reconfigure'
        from /opt/chef/embedded/apps/chef/lib/chef/application.rb:56:in `run'
        from /opt/chef/embedded/apps/chef/bin/chef-solo:25:in `<top (required)>'
        from /usr/bin/chef-solo:40:in `load'
        from /usr/bin/chef-solo:40:in `<main>'
ERROR: RuntimeError: chef-solo failed. See output above.
[infra@goadev5001 chef-pfsys]$ 

I looked into the chef-solo process. It seems chef-solo was called with broken arguments form the beginning.

I suspect knife-solo is clobbering the given parameter at some point.

matschaffer commented 9 years ago

Yeah, it definitely is. This line would be where I suspect.

It's trying to replace calls to "sudo" with different calls depending on the environment you're running on.

Switching to .sub might be good enough to fix it, but I'd want to do a full integration test run to be sure.