sous-chefs / homebrew

Development repository for the homebrew cookbook
https://supermarket.chef.io/cookbooks/homebrew
Apache License 2.0
151 stars 136 forks source link

homebrew_package fails too early if homebrew is installed but homebrew_user has been removed #76

Closed spkane closed 5 years ago

spkane commented 9 years ago

There is a bit of a chicken and egg problem here, that should fail more gracefully.

A run-list that creates an OS X user, and then installs homebrew for that user, works as expected.

However, if you later remove the user (like during testing), everything breaks badly (unless you also uninstall homebrew), even though the user would be re-created before it is actually needed by homebrew or any package installs.

This seems to happen because a cookbook library detects that homebrew is installed and has a homebrew_owner defined, and then can't find that user, and fails. It might be better, if this only generated a warning and continued. That way if this user is recreated before the first package call, things should still work fine.

If you get to the first package and the user still doesn't exist, this seems like a better time to have a fatal error.

spkane commented 9 years ago

Here is the stack trace:

==> default:
==> default:
==> default: ================================================================================
==> default:
==> default: Recipe Compile Error in /var/chef/cache/cookbooks/nr_base/recipes/default.rb
==> default:   ================================================================================
==> default:
==> default:
==> default: ArgumentError
==> default:   -------------
==> default:   can't find user for 499
==> default:
==> default:   Cookbook Trace:
==> default:   ---------------
==> default:     /var/chef/cache/cookbooks/homebrew/libraries/homebrew_mixin.rb:34:in `homebrew_owner'
==> default:     /var/chef/cache/cookbooks/homebrew/recipes/default.rb:27:in `from_file'
==> default:     /var/chef/cache/cookbooks/nr_base/recipes/default.rb:29:in `from_file'
==> default:
==> default:   Relevant File Content:
==> default:
==> default: ----------------------
==> default:   /var/chef/cache/cookbooks/homebrew/libraries/homebrew_mixin.rb:
==> default:
==> default:    27:  module Homebrew
==> default:    28:    # Homebrew
==> default:    29:    module Mixin
==> default:    30:      def homebrew_owner
==> default:    31:        if defined?(Chef::Mixin::HomebrewUser)
==> default:    32:          begin
==> default:    33:            require 'etc'
==> default:    34>>           @homebrew_owner ||= ::Etc.getpwuid(Chef12HomebrewUser.new.find_homebrew_uid).name
==> default:    35:          rescue Chef::Exceptions::CannotDetermineHomebrewOwner
==> default:    36:            @homebrew_owner ||= calculate_owner
==> default:    37:          end
==> default:    38:        else
==> default:    39:          @homebrew_owner ||= calculate_owner
==> default:    40:        end
==> default:    41:      end
==> default:    42:
==> default:    43:      private
==> default:
==> default:
==> default:
==> default:   Running handlers:
==> default: [2015-09-20T12:15:14+00:00] ERROR: Running exception handlers
==> default:   Running handlers complete
==> default:
==> default: [2015-09-20T12:15:14+00:00] ERROR: Exception handlers complete
==> default:
==> default: Chef Client failed. 1 resources updated in 878.327365 seconds
==> default: [2015-09-20T12:15:14+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
==> default: [2015-09-20T12:15:14+00:00] ERROR: can't find user for 499
==> default: [2015-09-20T12:15:14+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
bdwyertech commented 8 years ago

@spkane this may be addressed by the lazy evaluation in https://github.com/chef-cookbooks/homebrew/pull/86

bdwyertech commented 8 years ago

I take that back. In your case, the problem is that the homebrew_user definition is being ran at compile time. That would also have to be made lazy too, causing it to be called at runtime when the resource is executed and the user exists.

tas50 commented 5 years ago

homebrew_package is part of the chef-client itself at this point. I'm going to close this out now since there's nothing to fix in this cookbook. If you still thing this is an issue please submit the issue against the chef project itself.