-
-
Save hesco/50434ae9b36b1b422e97 to your computer and use it in GitHub Desktop.
This file contains 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
On and off for months now I have returned to the issue of deploying a | |
multi-vagrant-box development environment, but without success. | |
In a conversation today a colleague suggested that the issue was likely | |
baked into our vagrant base box, which I built early this past year from | |
an ISO blessed by the operations folks in the company. He suggests they | |
somehow disabled deploying a second nic, and udev/rules.d script which the | |
SUSE documentation promises I might find at: | |
/etc/udev/rules.d/70-persistent-net.rules | |
is not to be found, suggesting that there might be something to his theory. | |
So I have been hard-coding a work-around, and am quite pleased with the | |
progress I enjoyed this afternoon. I am able to successfully use the | |
Vagrantfile reproduced here to add a nic, and configure it with an IP. | |
All that to explain why I am jumping through the hoops seen here, | |
at least I am no longer filing bug reports against the vagrant library. | |
The issue I face now is that I seem unable to effectively parameterize the | |
ruby method which is passing the IP to the network configuration. The | |
jenkins slave node runs first and its IP gets applied to both that node | |
and to the jenkins master node, leaving the two nodes unable to communicate | |
with one another. | |
Any thoughts on how to resolve this issue would be appreciated. I still | |
struggle a bit with ruby, which I have only started using somewhat regularly | |
in the past year. | |
Thanks for your time reviewing this code. | |
-- Hugh |
This file contains 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
https://eval.in/487971 | |
https://docs.vagrantup.com/v2/multi-machine/ | |
https://gist.github.com/yzguy/70876b1b2d6489b5b578 | |
https://gist.github.com/yzguy/c3a22df8f45e0585cf85 | |
https://github.com/mitchellh/vagrant/issues/6142 | |
posted to #ruby@irc.freenode.net -- | |
toretore: your advice that DRY is over-rated, along with Yzguy's wet Vagrantfile, along with my | |
*.vm.network . . . auto_config: false, plus my shell provisioner using the get_network_config_script( ip ), | |
at long last got me to the promised land. I now have a functioning multi-node Vagrantfile !!! | |
which builds across the vpn in 20 minutes, although those two nodes only take 11 minutes in the office. |
This file contains 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
base_box = 'sles11sp3_employer_pe_agent_v0.9.1' | |
nodes = { | |
'slave' => { 'ram' => 2048, 'ip' => '192.168.51.111', 'listen' => false, 'host' => 'slave.jenkins' }, | |
'jenkins' => { 'ram' => 6144, 'ip' => '192.168.51.101', 'listen' => true, 'host' => 'jenkins' }, | |
} | |
def get_network_config_script ( ip ) | |
File.write("/tmp/method_says_ip", ip) | |
$configure_network = <<SCRIPT | |
ip="#{ip}" | |
INTERFACE=$(ip link show | grep DOWN | awk '{ print $2 }' | sed "s,:,,") | |
echo "$ip : $INTERFACE" > /tmp/computed_interface | |
NIC="/etc/sysconfig/network/ifcfg-$INTERFACE" | |
if [ -d "$NIC" ]; then | |
rm "$NIC" | |
fi | |
echo "#VAGRANT-BEGIN" >> $NIC | |
echo "# The contents below are automatically generated by Vagrant. Do not modify." >> $NIC | |
echo "BOOTPROTO='static'" >> $NIC | |
echo "IPADDR='$ip'" >> $NIC | |
echo "NETMASK='255.255.255.0'" >> $NIC | |
echo "DEVICE='eth1'" >> $NIC | |
echo "PEERDNS=no" >> $NIC | |
echo "STARTMODE='auto'" >> $NIC | |
echo "USERCONTROL='no'" >> $NIC | |
echo "#VAGRANT-END" >> $NIC | |
/sbin/ifup "$INTERFACE" | |
SCRIPT | |
end | |
Vagrant.configure(2) do |config| | |
nodes.each do | host, foo | | |
File.write("/tmp/#{nodes[host]['host']}", nodes[host]) | |
# File.write("/tmp/#{nodes[#{host}]['host']}", nodes[#{host}]['ip']) | |
# if node['listen'] == true then | |
# config.vm.network "forwarded_port", guest: 8080, host: 9080 | |
# end | |
config.vm.provider "virtualbox" do |v| | |
v.memory = nodes[host]['ram'] | |
v.cpus = 2 | |
end | |
config.vm.define "#{nodes[host]['host']}" do |jenkins| | |
jenkins.vm.box = base_box | |
jenkins.vm.hostname = "#{nodes[host]['host']}.vagrant" | |
jenkins.ssh.private_key_path = 'insecure_key' | |
jenkins.vm.network "private_network", ip: "#{nodes[host]['ip']}", auto_config: false | |
config.vm.synced_folder "fixtures/etc/puppet/hieradata", "/tmp/vagrant-puppet/hieradata" | |
# $configure_network_#{host} = get_network_config_script( nodes[host]['ip'] ) | |
# config.vm.provision "shell", inline: "$configure_network_#{host}" | |
File.write("/tmp/ip_#{nodes[host]['host']}", nodes[host]['ip']) | |
config.vm.provision "shell", inline: get_network_config_script( nodes[host]['ip'] ) | |
config.vm.provision "puppet" do |puppet| | |
puppet.manifests_path = "fixtures/etc/puppet/environments/production/manifests" | |
puppet.manifest_file = "nodes.pp" | |
puppet.module_path = [ '../', 'fixtures/etc/puppet/modules', 'fixtures/etc/puppet/environments/production/modules' ] | |
puppet.facter = { | |
"vagrant" => "1" | |
} | |
puppet.hiera_config_path = "fixtures/etc/puppet/hiera.yaml" | |
puppet.working_directory = "/tmp/vagrant-puppet" | |
# puppet.options = "--verbose --debug" | |
# puppet.options = "--parser future" | |
end | |
end | |
end | |
end |
This file contains 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
base_box = 'sles11sp3_employer_pe_agent_v0.9.1' | |
nodes = { | |
'slave' => { 'ram' => 2048, 'ip' => '192.168.51.111', 'listen' => false, 'host' => 'slave.jenkins' }, | |
'jenkins' => { 'ram' => 6144, 'ip' => '192.168.51.101', 'listen' => true, 'host' => 'jenkins' }, | |
} | |
def get_network_config_script ( ip ) | |
File.write("/tmp/method_says_ip", ip) | |
configure_network = <<SCRIPT | |
ip="#{ip}" | |
INTERFACE=$(ip link show | grep DOWN | awk '{ print $2 }' | sed "s,:,,") | |
echo "$ip : $INTERFACE" > /tmp/computed_interface | |
NIC="/etc/sysconfig/network/ifcfg-$INTERFACE" | |
if [ -d "$NIC" ]; then | |
rm "$NIC" | |
fi | |
echo "#VAGRANT-BEGIN" >> $NIC | |
echo "# The contents below are automatically generated by Vagrant. Do not modify." >> $NIC | |
echo "BOOTPROTO='static'" >> $NIC | |
echo "IPADDR='$ip'" >> $NIC | |
echo "NETMASK='255.255.255.0'" >> $NIC | |
echo "DEVICE='eth1'" >> $NIC | |
echo "PEERDNS=no" >> $NIC | |
echo "STARTMODE='auto'" >> $NIC | |
echo "USERCONTROL='no'" >> $NIC | |
echo "#VAGRANT-END" >> $NIC | |
/sbin/ifup "$INTERFACE" | |
SCRIPT | |
end | |
Vagrant.configure(2) do |config| | |
nodes.each do | host, foo | | |
File.write("/tmp/#{nodes[host]['host']}", nodes[host]) | |
# File.write("/tmp/#{nodes[#{host}]['host']}", nodes[#{host}]['ip']) | |
# if node['listen'] == true then | |
# config.vm.network "forwarded_port", guest: 8080, host: 9080 | |
# end | |
config.vm.provider "virtualbox" do |v| | |
v.memory = nodes[host]['ram'] | |
v.cpus = 2 | |
end | |
config.vm.define "#{nodes[host]['host']}" do |jenkins| | |
jenkins.vm.box = base_box | |
jenkins.vm.hostname = "#{nodes[host]['host']}.vagrant" | |
jenkins.ssh.private_key_path = 'insecure_key' | |
jenkins.vm.network "private_network", ip: "#{nodes[host]['ip']}", auto_config: false | |
# $configure_network_#{host} = get_network_config_script( nodes[host]['ip'] ) | |
# config.vm.provision "shell", inline: "$configure_network_#{host}" | |
File.write("/tmp/ip_#{nodes[host]['host']}", nodes[host]['ip']) | |
config.vm.provision "shell", inline: get_network_config_script( nodes[host]['ip'] ) | |
end | |
end | |
config.vm.synced_folder "fixtures/etc/puppet/hieradata", "/tmp/vagrant-puppet/hieradata" | |
config.vm.provision "puppet" do |puppet| | |
puppet.manifests_path = "fixtures/etc/puppet/environments/production/manifests" | |
puppet.manifest_file = "nodes.pp" | |
puppet.module_path = [ '../', 'fixtures/etc/puppet/modules', 'fixtures/etc/puppet/environments/production/modules' ] | |
puppet.facter = { | |
"vagrant" => "1" | |
} | |
puppet.hiera_config_path = "fixtures/etc/puppet/hiera.yaml" | |
puppet.working_directory = "/tmp/vagrant-puppet" | |
# puppet.options = "--verbose --debug" | |
# puppet.options = "--parser future" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment