Detecting machine state in Vagrantfile

瀏覽次數:17 次
跳到第一則未讀訊息

Sam Kaplan

未讀,
2017年11月13日 下午3:50:252017/11/13
收件者:Vagrant

Hi,

In a Vagrantfile, is it possible to detect whether a machine is already created? I'm trying to run a block of code only if "vagrant up" is creating a new box (and not when re-booting an existing one).

Even a provider-specific method would be helpful -- I'm only using Virtualbox.

Thanks,
Sam

Alvaro Miranda Aguilera

未讀,
2017年11月15日 凌晨3:46:372017/11/15
收件者:vagra...@googlegroups.com
Hello

By default provisioning scripts only run at creation time.

Next time you do vagrant up/reload the provisioning doesn't run at all.

If there are some provisioning you want to have always to run, you can add    

,run: "always"


Does this helps?
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/c3ef20a6-5ef1-4253-a076-43d381bda8fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Sam Kaplan

未讀,
2017年11月15日 上午9:42:402017/11/15
收件者:Vagrant
Not quite...I'm not worried about provisioning scripts in this case.

I have a block in my Vagrantfile like:

  config.vm.provider "virtualbox" do |vb|
    vb.cpus = ENV["VAGRANT_CPU"] || "2"
    vb.memory = ENV["VAGRANT_MEM"] || "2048"
  end


so you can specify cpu and memory size in environment variables. But this also means you have to specify them every time you boot the machine, or they will get overwritten by the defaults. If I had a way to detect that the machine was already created, then I could avoid setting the config values in that case.

Thanks,
Sam


On Wednesday, November 15, 2017 at 3:46:37 AM UTC-5, Alvaro Miranda Aguilera wrote:
Hello

By default provisioning scripts only run at creation time.

Next time you do vagrant up/reload the provisioning doesn't run at all.

If there are some provisioning you want to have always to run, you can add    

,run: "always"


Does this helps?
Alvaro
On Mon, Nov 13, 2017 at 9:50 PM, Sam Kaplan <stka...@gmail.com> wrote:

Hi,

In a Vagrantfile, is it possible to detect whether a machine is already created? I'm trying to run a block of code only if "vagrant up" is creating a new box (and not when re-booting an existing one).

Even a provider-specific method would be helpful -- I'm only using Virtualbox.

Thanks,
Sam

--
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+...@googlegroups.com.



--
Alvaro

Alvaro Miranda Aguilera

未讀,
2017年11月15日 下午5:19:132017/11/15
收件者:vagra...@googlegroups.com
Hello

There was an old email once that used ruby magic to detect if the id of the vm existed, but i don't think is needed.

check for a local file, if doesn't exist, set those values.

and in a provision script, just do `touch /vagrant/.provisioned` or similar.

will be more easy to read.

My 2 cents

alvaro.

To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/824fbc3f-d644-4230-bc95-a425543aca49%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

回覆所有人
回覆作者
轉寄
0 則新訊息