When i do a vagrant provisioning, can i ignore some provision codes from Vagrantfile on vagrant reload?

末鹿安然 提交于 2020-01-24 12:55:06

问题


In my Vagrantfile, I have two shell provisions: one is for installing system dependencies for my project, and another is for starting up nginx server.

So what I wanted to have is when I vagrant reload --provision, can I ignore the provision for installing the system dependencies, and just start up the nginx server instead?

Sample code:

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    ...

    # Ignore this line on VM reload
    config.vm.provision 'shell', path: 'provision/install.sh'

    # Execute this one only on VM reload
    config.vm.provision 'shell', path: 'provision/start_nginx.sh'

    ...

end

回答1:


One simple solution, but a little bit hack method is

You can pass environment variables while running vagrant reload command like this

RELOAD=true vagrant reload --provision

then in VagrantFile

VAGRANTFILE_API_VERSION = '2'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

    ...

    # Ignore this line on VM reload
    if (ENV['RELOAD'] != true)
        config.vm.provision 'shell', path: 'provision/install.sh'
    end

    # Execute this one only on VM reload
    config.vm.provision 'shell', path: 'provision/start_nginx.sh'

    ...

end


来源:https://stackoverflow.com/questions/27221619/when-i-do-a-vagrant-provisioning-can-i-ignore-some-provision-codes-from-vagrant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!