Skip to content

Instantly share code, notes, and snippets.

@stuart-warren
Last active March 23, 2022 21:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuart-warren/6294939 to your computer and use it in GitHub Desktop.
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
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