我对用于配置Vagrant的ruby语法感到困惑。尤其是使用这种构造。这是一个赋值,一个方法调用,还是别的什么?它是纯正的红宝石还是流浪特有的方言?
config.vm.network "forwarded_port", guest: 3000, host: 3000还有这张。ansible是赋值还是参数,ansible|从何而来?
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioners/docker.yml"
end我可以在哪里找到关于这些特定表达式的更多信息?
发布于 2016-10-09 01:18:17
发布于 2019-03-31 00:19:24
Vagrantfile是用标准Ruby语法编写的。
下面是一个Vagrantfile示例
Vagrant.configure("2") do |config|
# this is an evaluation statement
# .box is an string attribute
config.vm.box = "debian/stretch64"
# this is a method call
# .synced_folder is a method that takes two positional arguments ('synced_folder', '/vagrant'),
# followed by some keyword arguments (disabled: true)
config.vm.synced_folder 'synced_folder', '/vagrant', disabled: true
# this is a method call, followed by a "do ... end" block
# .provider is a method that takes one positional argument (:libvirt)
config.vm.provider :libvirt do |node|
# these are two evaluation statements
node.cpus = 4
node.memory = 4096
end
end在官方文档中,您可以看到"config.vm.box (string)“中的变量"string”,但后面没有config-vm-provider和config-vm-synced_folder方法。
我也对Vagrantfile的语法感到困惑,即使在阅读了官方文档之后也是如此。我认为这是因为Ruby与我以前使用的其他语言相比,在我看来非常不同。
https://stackoverflow.com/questions/39929762
复制相似问题