Main issue I found: https://github.com/mitchellh/vagrant/issues/1867 . 
Trying to
skim the code + read issues, it seems that the problem is that the chosen 
provider 
isn't guaranteed to be known yet when the Vagrantfile is being parsed, 
which means 
that parsing the argument list yourself is likely going to be the main 
"solution" for some 
time as real support might require a non-trivial rewrite. 

For what it's worth, here's what I'm using. This is literally the first 
Ruby I've 
ever written, so if someone could improve it to search the entire arg array 
instead
of assuming provider is the first option given that would be great. 

# Workaround for mitchellh/vagrant#1867
if ARGV[1] and \
   (ARGV[1].split('=')[0] == "--provider" or ARGV[2])
  provider = (ARGV[1].split('=')[1] || ARGV[2])
else
  provider = (ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
end
puts "Detected #{provider}"

if provider == "aws"
  puts 'If you want to use the AWS provider, you must provide these 
variables: '
  <code snip>
end


Thanks,
Hamilton

On Wednesday, July 23, 2014 3:59:53 AM UTC-4, Torben Knerr wrote:
>
> Having access to the provider sounds useful, did anyone already create an 
> issue for it?
> https://github.com/mitchellh/vagrant/issues
>
>
>
> On Mon, Jul 21, 2014 at 10:09 PM, Benjamen Keroack <[email protected] 
> <javascript:>> wrote:
>
>> I just had to implement the hack from earlier in the thread (involving 
>> ARGV).
>>
>> Basically I need to set a variable based on the provider name and use it 
>> later on in provision blocks, but there's no way to do this in Vagrant 
>> without that type of hack, unfortunately. Global variables
>> set in provider blocks are not visible outside the block.
>>
>>
>> On Wednesday, May 28, 2014 9:32:21 AM UTC-7, Brian Gonzalez wrote:
>>>
>>>
>>> You could also check the provider type from with the provider block, and 
>>> set up some conditional config there:
>>>
>>>
>>>   config.vm.provider "digital_ocean" do |provider|
>>>
>>>     puts "* Using Digital Ocean Provider *"
>>>     config.ssh.private_key_path = "~/.ssh/id_rsa" if provider.is_a? 
>>> VagrantPlugins::DigitalOcean::Config
>>>
>>>     provider.client_id = DIGITAL_OCEAN_CLIENT_ID
>>>     provider.api_key = DIGITAL_OCEAN_API_KEY
>>>     provider.image = "Ubuntu 13.10 x64"
>>>     provider.region = "San Francisco 1"
>>>   end
>>>
>>>
>>>
>>> On Tuesday, November 12, 2013 9:14:14 AM UTC-8, Teemu Matilainen wrote:
>>>>
>>>> On Tue, Nov 12, 2013 at 1:39 PM, Shawn Neal <[email protected]> wrote:
>>>>
>>>>> You can put something like this in your Vagrantfile:
>>>>>
>>>>>   provider = (ARGV[2] || :virtualbox).to_sym
>>>>>
>>>>
>>>> The default provider can also be set by an environment variable:
>>>>
>>>> provider = (ARGV[2] || ENV['VAGRANT_DEFAULT_PROVIDER'] || 
>>>> :virtualbox).to_sym
>>>>  
>>>>
>>>>> While this works, I tend to avoid doing things like this. Instead I 
>>>>> put things like this into a config file that is conditionally loaded if 
>>>>> they exist or in environment variables.
>>>>>
>>>>
>>>> Yeah, that feels really fragile. =)
>>>>
>>>> -- 
>>>> Cheers,
>>>>   Teemu 
>>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Vagrant" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to