cluster_size = 5
def build_namenode_box( config )
vmname = "namenode"
config.vm.define vmname.to_sym do |namenode|
namenode.vm.box = "dummy"
namenode.vm.provision :chef_solo, preserve_order: true do |chef|
chef.cookbooks_path = "cookbooks"
chef.roles_path = "roles"
chef.add_role "test"
chef.data_bags_path = "data_bags"
chef.add_recipe "cloudera::namenode"
chef.add_recipe "cloudera-cluster"
end
namenode.vm.provision :hostmanager
namenode.vm.provision :shell, :inline => $script
end
end
def build_slaves_boxes( config, cluster_size )
(1..cluster_size).each do |i|
vmname = "slave#{i}"
config.vm.define vmname.to_sym do |slave|
slave.vm.box = "dummy"
slave.vm.provision :chef_solo, preserve_order: true do |chef|
chef.cookbooks_path = "cookbooks"
chef.roles_path = "roles"
chef.add_role "test"
chef.data_bags_path = "data_bags"
chef.add_recipe "cloudera::datanode"
chef.add_recipe "cloudera-cluster"
end
slave.vm.provision :shell, :inline => $slavescript
end
end
end
Vagrant.configure("2") do |config|
config.omnibus.chef_version = :latest
config.vm.provider :aws do |aws, override|
config.vm.box = "dummy"
aws.access_key_id = "myid"
aws.secret_access_key = "my_key"
aws.keypair_name = "my_key"
aws.ami = "ami-7747d01e"
aws.security_groups = ["my_group"]
override.ssh.username = "ubuntu"
override.ssh.private_key_path = "#{current_dir}/my_key.pem"
end
config.vm.provider :virtualbox do |v|
config.vm.box = "precise64"
config.vm.box_url = "https://vagrantcloud.com/chef/ubuntu-12.04/version/1/provider/virtualbox.box"
v.customize ["modifyvm", :id, "--memory", "1024"]
end
#block the program until it returns.
build_namenode_box( config )
# have to wait until the build_namenode_box() returns
build_slaves_boxes( config, cluster_size )
end
我正在构建一个Vagrantfile(在Ruby中)来创建一个Cloudera Hadoop集群。它创建的问题如下:
Vagrant不执行订单(不要等到订单定义vm完成执行)。
所以我需要等到namenode
完成,因为从属数据节点在jobtracker之前启动。解决方案?阻止build_namenode_box()
函数直到完成。我在Ruby中是非常原始的,那么如何在执行build_namenode_box()
函数之前编写一个等待build_slaves_boxes()
返回的函数拦截器?我如何使用yield
来实现这一目标?
答案 0 :(得分:0)
在普通的Vagrant中,这是不可能的,因为您注意到它不支持VM间依赖性。您可以使用以正确顺序调用vagrant up $name
的外部脚本或使用chef-metal之类的更复杂的内容来管理配置。