Independent provider and provisioning in same Vagrantfile

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Independent provider and provisioning in same Vagrantfile

joao.machado
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Independent provider and provisioning in same Vagrantfile

joao.machado
Found a typo: where it reads "If I have only these providers set up" it should be "If I have only one these providers set up"

On Thursday, October 19, 2017 at 11:30:22 AM UTC+1, [hidden email] 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/c18c5ac0-a7ec-4ae1-8609-1251560c1383%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Independent provider and provisioning in same Vagrantfile

Alvaro Miranda Aguilera
In reply to this post by joao.machado
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, <[hidden email]> 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com.
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 [hidden email].
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 | Threaded
Open this post in threaded view
|

Re: Independent provider and provisioning in same Vagrantfile

joao.machado
Hello Alvaro!

Thanks for your reply. I ended up rethinking my process and decided to keep two distinct Vagrantfiles for each purpose. I'll try your approach when I get the chance and post some feedback here.

Again, thank you for your help.

Cheers!

On Thursday, October 19, 2017 at 12:22:02 PM UTC+1, Alvaro Miranda Aguilera wrote:
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, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="-G6wdLEgBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">joao.m...@...> 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 - <a href="https://www.hashicorp.com/community-guidelines.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;">https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: <a href="https://github.com/mitchellh/vagrant/issues" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="-G6wdLEgBQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vagrant-up+...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/vagrant-up/66c66570-f25a-4e58-aa21-72f052050ed5%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/5ccc8f12-1db9-405d-b44e-e9ee32466890%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.