matschaffer / knife-solo

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

Make `check_chef_version` configurable via knife.rb #535

Closed yacn closed 6 years ago

yacn commented 6 years ago

changes

Updates SoloCook#check_chef_version to now check knife.rb for a key :solo_chef_version which specifies the version constraint required. We need this as a way to bail out of a Chef run with better error messages. The current constraint of >=0.10.4 is satisfied by the Vagrant box we're using (phusion 14.04) but we have cookbooks that require Chef 12 -- we get around this by requiring knife solo prepare to run before knife solo cook. However, sometimes people forget to run it and encounter the following error because we have cookbooks w/ metadata.rb's that are updated for Chef 12:

[2018-08-31T23:28:09+00:00] ERROR: undefined method `source_url' for #<Chef::Cookbook::Metadata:0x000000032361f0>
[2018-08-31T23:28:09+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

They then message an ops person because it looks like something broke when really they just need to run knife solo prepare.

testing

# without knife[:solo_chef_version] defined
➜ tail -1 ~/.chef/knife.rb
#knife[:solo_chef_version] = '>= 12.0.0'
➜ knife solo cook test.local nodes/test.local.json
Running Chef on test.local...
Checking Chef version...
chef_version_satisfies?(>=0.10.4) # this was debug output from me
Installing Berkshelf cookbooks to 'cookbooks'...
.... output ...
Running Chef: sudo chef-solo -c ~/chef-solo/solo.rb -j ~/chef-solo/dna.json
Starting Chef Client, version 11.12.2

Running handlers:
[2018-08-31T23:28:55+00:00] ERROR: Running exception handlers
Running handlers complete

[2018-08-31T23:28:55+00:00] ERROR: Exception handlers complete
[2018-08-31T23:28:55+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.851528323 seconds
[2018-08-31T23:28:55+00:00] ERROR: undefined method `source_url' for #<Chef::Cookbook::Metadata:0x00000004699ca0>
[2018-08-31T23:28:55+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.

vs with the new option added to knife.rb

➜ tail -1 ~/.chef/knife.rb
knife[:solo_chef_version] = '>= 12.0.0'
➜ knife solo cook test.local nodes/test.local.json
Running Chef on test.local...
Checking Chef version...
ERROR: RuntimeError: Couldn't find Chef >= 12.0.0 on apollo.local. Please run `knife solo prepare isaacboehman@test.local -o ForwardAgent=yes` to ensure Chef is installed and up to date.
coveralls commented 6 years ago

Coverage Status

Coverage increased (+0.7%) to 90.78% when pulling ed9567a6cf8819740d9724fa7f4a9c3dd04aab58 on yacn:feature/configure-acceptable-chef into 0026879782b430d81a4211abb6fe43abe1602fee on matschaffer:master.

yacn commented 6 years ago

@matschaffer not a problem, I've pushed the requested changes.

matschaffer commented 6 years ago

Great, thanks!