tmatilai / vagrant-proxyconf

Vagrant plugin that configures the virtual machine to use proxies
MIT License
531 stars 74 forks source link

Chef proxy detection broken with multi-vm Vagrantfiles #101

Closed jperville closed 9 years ago

jperville commented 9 years ago

It seems that the chef proxy settings are not applied when the Vagrantfile defines more than one VM.

When the Vagrantfile defines a single VM (with config.vm.provision :chef_solo etc) I can find the expected *_proxy entries in /tmp/vagrant-chef-2/solo.rb.

However, when the Vagrantfile defines several VMs (as below), all the *_proxies entries in /tmp/vagrant-chef-2/solo.rb are set to nil.

config.vm.define "apps", :primary => true, :autostart => true do |apps|
    apps.vm.hostname = "apps-vm"
    ....
    apps.vm.provision "chef_solo" do |chef|
      chef.json = { ... }
      chef.add_recipe(...)
  end
end

I believe the reason lies in https://github.com/tmatilai/vagrant-proxyconf/blob/master/lib/vagrant-proxyconf/action/configure_chef_proxy.rb#L46 where the chef_provisioners method only scans 'config.vm.provisionners' and not the per-VM provisionners.

I found out about the issue because it my 'remote_file' resources suddenly broke while I was refactoring a huge VM into several smaller ones (my firewall blocks non-proxied http requests).

tmatilai commented 9 years ago

Thanks, this really seems like a bug. I don't use multi-vm setups so it never hit me. Are you willing to try to fix this? =)

jperville commented 9 years ago

HI @tmatilai, I'd love to help fix that issue; it looks doable even for someone with limited experience of Vagrant plugins like me. I should have some free time around Christmas and will look into it.

For the moment I work around the issue with a chef.custom_config_path containing the following:

http_proxy ENV['http_proxy'] unless String(ENV['http_proxy']).empty?
https_proxy ENV['https_proxy'] unless String(ENV['https_proxy']).empty?
ftp_proxy ENV['ftp_proxy'] unless String(ENV['ftp_proxy']).empty?
no_proxy ENV['no_proxy'] unless String(ENV['no_proxy']).empty?
tmatilai commented 9 years ago

@jperville great! Feel free to ping if you have questions.

jperville commented 9 years ago

I have submitted a very modest PR (#103), which should do the trick. I can't believe that it was as easy as detecting the chef provisioners on the type attribute rather than on the name one.

jperville commented 9 years ago

I have done some investigation and it seems that:

I updated my fix to detect the chef provisioner using the type method (if responds_to?), with fallback to the name method). I also reported the issue to Vagrant (mitchellh/vagrant#5069).