gpt4 book ai didi

vagrant - 仅在配置时在 Vagrantfile 中运行代码

转载 作者:行者123 更新时间:2023-12-04 13:32:21 24 4
gpt4 key购买 nike

我想在运行 vagrant up 时在屏幕上显示一些文本(或 vagrant provision 等)当且仅当 正在配置。 (对于 vagrant up 它只在第一次运行,或者如果特别强制使用 --provision 。)

如何才能做到这一点?

最佳答案

添加 shell 配置程序可能是最简单的解决方案,它通过 SSH 在 VM 上执行的成本很小。

另一种选择是使用 vagrant-host-shell插入:

Vagrant.configure('2') do |config|
# other config and provisioners
# [...]

config.vm.provision :host_shell, inline: 'echo "Provisioned!"'
end

如果你喜欢过度设计,你甚至可以在 Vagrantfile 中制作自己的插件。 ;)

class EchoPlugin < Vagrant.plugin('2')
class EchoAction
def initialize(app, env)
@app = app
end

def call(env)
@app.call(env)
puts "Provisioned!"
end
end

name 'echo'

action_hook 'echo' do |hook|
hook.before Vagrant::Action::Builtin::Provision, EchoAction
end
end

Vagrant.configure('2') do |config|
# ...
end

关于vagrant - 仅在配置时在 Vagrantfile 中运行代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21890104/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com