Can you try like this:


Vagrant.configure(2) do | config |

  # doesn't work:
  # provider_is_aws  = (!ARGV.nil? && ARGV.join('').include?('
provider=aws'))


  # unless provider_is_aws # doesn't isolate the configuration

  config.vm.provider :virtualbox do |v|
    # several config.vm options
    # ...
    v.vm.provision "ansible" do |ansible|
      ansible.playbook = "local_playbook.yml"
    end
  end
  # end # unless block

  # if provider_is_aws # doesn't isolate the configuration
  config.vm.provider :aws do |aws, override|
    # several aws. options
    # ...
    override.vm.provision "Ansible_Local", type: "ansible_local" do |ansible
|
      ansible.playbook = "aws_playbook.yml"
    end
  end
  # end # if block


end

On Thu, Oct 19, 2017 at 12:30 PM, <joao.mach...@omibee.com> wrote:

> I have a specific use case for Vagrant with which I'm struggling a bit.
>
> We need to have on the same Vagrantfile a way to roll a local development
> VM and/or an AWS instance. For this I thought of using 2 different
> providers, a virtualbox provider and the vagrant-aws provider plugin.
>
> If I have only these providers set up in the Vagrantfile, it works as
> expected. However, if I
>
> vagrant up --provider=virtualbox
>
> the provision block I have setup in the Virtualbox provider block runs
> *twice*. I have tried isolating each provider's configuration and
> provisioning inside if-then blocks that look at the ARGV array, but Vagrant
> seems to ignore this.
>
> My final goal is to have at a project level, a way that allows my
> developer colleagues to *vagrant up* locally so that they can work on the
> project, but, at a different time, different host and by a different
> process, be able to *vagrant up --provider=aws* to roll a staging
> environment for the same project. Please note that I need different
> provisioning for either the local VM with Virtualbox or the staging
> instance on AWS. I also *don't* want the provisioning of each provider
> mixed up *or* both providers being setup at the same time.
>
> Does anyone have any insight on how to do this? Vagrant's documentation on
> Hashicorp's website is a bit misleading as I thought I could isolate
> different procedures in the same Vagrantfile, but I'm not sure if I'm doing
> it wrong or if it's not possible at all.
>
> My Vagrantfile looks something like this at the moment:
>
>
> Vagrant.configure(2) do | config |
>
>   # doesn't work:
>   # provider_is_aws  = (!ARGV.nil? && ARGV.join('').include?('
> provider=aws'))
>
>
>   # unless provider_is_aws # doesn't isolate the configuration
>
>   config.vm.provider :virtualbox do |v|
>     # several config.vm options
>     # ...
>     config.vm.provision "ansible" do |ansible|
>       ansible.playbook = "local_playbook.yml"
>     end
>   end
>   # end # unless block
>
>   # if provider_is_aws # doesn't isolate the configuration
>   config.vm.provider :aws do |aws, override|
>     # several aws. options
>     # ...
>     override.vm.provision "Ansible_Local", type: "ansible_local" do |
> ansible|
>       ansible.playbook = "aws_playbook.yml"
>     end
>   end
>   # end # if block
>
>
> end
>
>
> If I *vagrant up --provider=virtualbox* the *local_playbook.yml *provisioner 
> runs
> twice (!). This makes absolutely no sense to me.
>
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in
> violation of those guidelines may result in your removal from this mailing
> list.
>
> GitHub Issues: https://github.com/mitchellh/vagrant/issues
> IRC: #vagrant on Freenode
> ---
> 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 vagrant-up+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com
> <https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Alvaro

-- 
This mailing list is governed under the HashiCorp Community Guidelines - 
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of 
those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
--- 
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 vagrant-up+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/CAHqq0exj1%3DmONPvNxrknMP1Oq791W%2BgG1kXxLEdgXdWke5fTVw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to