Last active
March 23, 2022 21:13
-
-
Save stuart-warren/6294939 to your computer and use it in GitHub Desktop.
Vagrant shell provisioning with variable arguments. This example iterates through an object and passes its keys and values as parameters to a shell script
http://docs.vagrantup.com/v2/provisioning/shell.html It also creates one node for each key, value pair
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vagrant.configure("2") do |config| | |
HADOOP_NODES = {'hd-master' => '192.168.40.10', | |
'hd-slave1' => '192.168.40.11', | |
'hd-slave2' => '192.168.40.12'} | |
HADOOP_NODES.each do |node_name, node_ip| | |
config.vm.provision :shell do |s| | |
s.inline = 'echo -e "$1\t$2" | sudo tee -a /etc/hosts' | |
s.args = "#{node_ip} #{node_name}" | |
end | |
end | |
HADOOP_NODES.each do |node_name, node_ip| | |
config.vm.define node_name.to_sym do |node_config| | |
node_config.vm.box = 'precise64' | |
node_config.vm.box_url = 'http://files.vagrantup.com/precise64.box' | |
node_config.vm.hostname = node_name | |
node_config.vm.network :private_network, :ip => node_ip | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment