mitchellh/vagrant-aws

Undefined HashMap method `except` with Vagrant 2.2.7

externl opened this issue ยท 23 comments

/Users/jenkins/.vagrant.d/gems/2.4.9/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/connect_aws.rb:41:in `call': undefined method `except' for #<Hash:0x0000000101596148> (NoMethodError)
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/warden.rb:57:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/builtin/before_trigger.rb:23:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/warden.rb:57:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/builtin/after_trigger.rb:26:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/warden.rb:57:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/builtin/config_validate.rb:25:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/warden.rb:57:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/builtin/before_trigger.rb:23:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/warden.rb:57:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/builder.rb:116:in `call'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/runner.rb:102:in `block in run'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/util/busy.rb:19:in `busy'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/action/runner.rb:102:in `run'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:238:in `action_raw'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:209:in `block in action'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:191:in `block in action'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:195:in `action'
	from /Users/jenkins/.vagrant.d/gems/2.4.9/gems/vagrant-aws-0.7.2/lib/vagrant-aws/provider.rb:32:in `state'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:532:in `state'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/machine.rb:146:in `initialize'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/vagrantfile.rb:81:in `new'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/vagrantfile.rb:81:in `machine'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:715:in `machine'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/plugin/v2/command.rb:180:in `block in with_target_vms'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/plugin/v2/command.rb:213:in `block in with_target_vms'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/plugin/v2/command.rb:212:in `map'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/plugin/v2/command.rb:212:in `with_target_vms'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/plugins/commands/status/command.rb:20:in `execute'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/cli.rb:66:in `execute'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/lib/vagrant/environment.rb:290:in `cli'
	from /opt/vagrant/embedded/gems/2.2.7/gems/vagrant-2.2.7/bin/vagrant:182:in `<main>'

Looks like activesupport is now missing. Maybe it was bundled with vagrant it previous version?

Actually nothing to do with activesupport. It looks like a change to the i18n package which was upgraded with Vagrant 2.2.7.

They originally provided Hash.except: https://github.com/ruby-i18n/i18n/blob/1e67c8dd80933703328be524d3d8c4f21cb8c5a3/lib/i18n/core_ext/hash.rb

Now it's https://github.com/ruby-i18n/i18n/blob/741add9dba3fe8189454f47c5774b45211ab11a9/lib/i18n/core_ext/hash.rb

A quick fix for anyone experiencing this issue is to place the following in your ~/.vagrant/Vagrantfile

class Hash
  def slice(*keep_keys)
    h = {}
    keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
    h
  end unless Hash.method_defined?(:slice)
  def except(*less_keys)
    slice(*keys - less_keys)
  end unless Hash.method_defined?(:except)
end

Vagrant.configure(2) do |config|
...

I've also seen this bug after upgrading to Vagrant 2.2.7. I downgraded to Vagrant 2.2.5 as a quick fix. I did not try @externl 's Quick fix yet.

I can confirm that @externl's workaround works.

Vagrant 2.2.7, ruby 2.7.0p0, Arch Linux.

I can confirm that @externl's workaround works.

Vagrant 2.2.7 Win10

Getting this issue as well. I just edited 'vagrant-aws/action/connect_aws.rb' line 41 to remove the 'except' call. That gave me lots of warnings but just seemed to work. I would think this is easy to fix no?

Can confirm the fix from @externl works as well.

Fix from @externl works for me as well. Ubuntu 18.04, Vagrant 2.2.7

Actually... what @externl said... if you add it near the top of connect_aws.rb seems to workaround (or maybe fix?) the issue. I opened ~/.vagrant.d/gems/2.6.6/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/connect_aws.rb and added, per @externl, just after the two require lines:

class Hash
  def slice(*keep_keys)
    h = {}
    keep_keys.each { |key| h[key] = fetch(key) if has_key?(key) }
    h
  end unless Hash.method_defined?(:slice)
  def except(*less_keys)
    slice(*keys - less_keys)
  end unless Hash.method_defined?(:except)
end

I have not studied the problem more in-depth. I just tried with vagrant 2.2.9 and plugin version 0.7.2.

The issue is that vagrant core upgraded a plugin which this project depends. Unfortunately the only real fix is for @mitchellh to fix or accept a PR fixing it.

The usage of except needs to be remove here.

somebody must have forked and fixed this.

@guzzijones I wonder if they abandoned this project :( ... I was considering forking it and review/apply the fixes I can see here... there are a few pull requests open. However, I do not use this nearly enough as to justify the time investment. I hope @mitchellh is ok.

A less intrusive way I've found works is putting @externl's solution in a separate file and adding to the Vagrantfile require_relative 'initializers/patches.rb'

Dunno if we can get one of the maintainers to merge this, but at least here's a minimal patch that should work. Testing it locally now. (FYI, @mitchellh seems like he might be busy running something...)

Why is this issue still not fixed, I saw it with 2.2.10 and mattock workaround still works

I have also encountered this issue in 2.2.10 just like @liangbin-pub (on MacOS Catalina 10.15.7)

As a temporary solution you can use my Gem vagrant-aws-mkubenka with fix based on #575.

Installation instructions:

vagrant plugin uninstall vagrant-aws
vagrant plugin install vagrant-aws-mkubenka --plugin-version "0.7.2.pre.24"
derks commented

Same issue, fix from @externl works for me as well on:

  • Vagrant: 2.2.13
  • AWS Plugin: 0.7.2

Same issue and @externl 's with @soulhunter 's updates works like a charm on:

  • Vagrant 2.2.14
  • AWS Plugin 0.7.2

is this broken on purpose to make vagrant hard to use?

require_relative worked for me.

@externl Thanks, worked for me as well.

Reported 1.5 years ago and still broken in the latest version (a fresh install) of vagrant. ๐Ÿ˜ž

$ vagrant --version
Vagrant 2.2.16
$ vagrant status
~/.vagrant.d/gems/2.6.7/gems/vagrant-aws-0.7.2/lib/vagrant-aws/action/connect_aws.rb:41:in `call': undefined method `except' for #<Hash:0x0000000002591a80> (NoMethodError)
        from /opt/vagrant/embedded/gems/2.2.16/gems/vagrant-2.2.16/lib/vagrant/action/warden.rb:48:in `call'
...

There hasn't been a new release since Jul 3, 2016. I think it's safe to say that this project has been abandoned.

there are still use cases for this! Why can't we get a new release? Not everyone is using Kubernetes and/or Docker for everything!