Advertisement
the-packet-thrower

Vagrantfile

Sep 2nd, 2021
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.63 KB | None | 0 0
  1. # Vagrantfile API/syntax version.
  2. VAGRANTFILE_API_VERSION = "2"
  3.  
  4. Vagrant.configure("#{VAGRANTFILE_API_VERSION}") do |config|
  5.   config.vm.box = "vyos/current"
  6.  
  7.   # Disble SSH Replacement
  8.   config.ssh.insert_key = false
  9.  
  10.   # Disable Plugin Updates
  11.   if Vagrant.has_plugin?("vagrant-vbguest")
  12.     config.vbguest.auto_update = false
  13.   end
  14.  
  15.   # Configure Shared Folder
  16.   config.vm.synced_folder ".", "/vagrant", disabled: true
  17.  
  18.   # VBOX
  19.   config.vm.provider "virtualbox" do |v|
  20.     v.memory = 1024
  21.     v.cpus = 1
  22.   end
  23.  
  24.   # Spine Routers
  25.   $spine01_script = <<-SCRIPT
  26. cat << EOF > /tmp/provision-template.sh
  27. #!/bin/vbash
  28. source /opt/vyatta/etc/functions/script-template
  29. set system host-name spine01
  30. set system domain-name the-packet-thrower.com
  31. set interface loopback lo address 192.168.255.1/32
  32. set interface ethernet eth1 address 10.1.11.254/24
  33. set interface ethernet eth2 address 10.1.12.254/24
  34. set interface ethernet eth3 address 10.1.13.254/24
  35. set protocols ospf area 0 network 0.0.0.0/0
  36. commit
  37. EOF
  38. SCRIPT
  39.  
  40.   $spine02_script = <<-SCRIPT
  41. cat << EOF > /tmp/provision-template.sh
  42. #!/bin/vbash
  43. source /opt/vyatta/etc/functions/script-template
  44. set system host-name spine02
  45. set system domain-name the-packet-thrower.com
  46. set interface loopback lo address 192.168.255.2/32
  47. set interface ethernet eth1 address 10.2.11.254/24
  48. set interface ethernet eth2 address 10.2.12.254/24
  49. set interface ethernet eth3 address 10.2.13.254/24
  50. set protocols ospf area 0 network 0.0.0.0/0
  51. commit
  52. EOF
  53. SCRIPT
  54.  
  55.   # Leaf Routers
  56.   $leaf01_script = <<-SCRIPT
  57. cat << EOF > /tmp/provision-template.sh
  58. #!/bin/vbash
  59. source /opt/vyatta/etc/functions/script-template
  60. set system host-name leaf01
  61. set system domain-name the-packet-thrower.com
  62. set interface loopback lo address 192.168.255.11/32
  63. set interface ethernet eth1 address 10.1.11.1/24
  64. set interface ethernet eth2 address 10.2.11.254/24
  65. set protocols ospf area 0 network 0.0.0.0/0
  66. commit
  67. EOF
  68. SCRIPT
  69.  
  70.   $leaf02_script = <<-SCRIPT
  71. cat << EOF > /tmp/provision-template.sh
  72. #!/bin/vbash
  73. source /opt/vyatta/etc/functions/script-template
  74. set system host-name leaf02
  75. set system domain-name the-packet-thrower.com
  76. set interface loopback lo address 192.168.255.12/32
  77. set interface ethernet eth1 address 10.1.12.1/24
  78. set interface ethernet eth2 address 10.2.12.254/24
  79. set protocols ospf area 0 network 0.0.0.0/0
  80. commit
  81. EOF
  82. SCRIPT
  83.  
  84.   $leaf03_script = <<-SCRIPT
  85. cat << EOF > /tmp/provision-template.sh
  86. #!/bin/vbash
  87. source /opt/vyatta/etc/functions/script-template
  88. set system host-name leaf03
  89. set system domain-name the-packet-thrower.com
  90. set interface loopback lo address 192.168.255.13/32
  91. set interface ethernet eth1 address 10.1.13.1/24
  92. set interface ethernet eth2 address 10.2.13.254/24
  93. set protocols ospf area 0 network 0.0.0.0/0
  94. commit
  95. EOF
  96.   SCRIPT
  97.  
  98.   (1..2).each do |i|
  99.     config.vm.define "SPINE0#{i}" do |spine|
  100.       spine.vm.network "private_network", auto_config: false, virtualbox__intnet: "spine0#{i}_to_leaf01"
  101.       spine.vm.network "private_network", auto_config: false, virtualbox__intnet: "spine0#{i}_to_leaf02"
  102.       spine.vm.network "private_network", auto_config: false, virtualbox__intnet: "spine0#{i}_to_leaf03"
  103.       spine.vm.provider :virtualbox do |vb|
  104.         vb.customize ['modifyvm',:id,'--nicpromisc2','allow-all']
  105.         vb.customize ['modifyvm',:id,'--nicpromisc3','allow-all']
  106.         vb.customize ['modifyvm',:id,'--nicpromisc4','allow-all']
  107.       end
  108.       if i === 1
  109.         spine.vm.provision "shell", inline: $spine01_script
  110.       end
  111.       if i === 2
  112.         spine.vm.provision "shell", inline: $spine02_script
  113.       end
  114.       spine.vm.provision "shell", inline: <<-EOC
  115. chmod 777 /tmp/provision-template.sh
  116. sg vyattacfg -c /tmp/provision-template.sh
  117. EOC
  118.     end
  119.   end
  120.   # Leaf Routers
  121.   (1..3).each do |i|
  122.     config.vm.define "LEAF0#{i}" do |leaf|
  123.       leaf.vm.network "private_network", auto_config: false, virtualbox__intnet: "spine01_to_leaf0#{i}"
  124.       leaf.vm.network "private_network", auto_config: false, virtualbox__intnet: "spine02_to_leaf0#{i}"
  125.       leaf.vm.provider :virtualbox do |vb|
  126.         vb.customize ['modifyvm',:id,'--nicpromisc2','allow-all']
  127.         vb.customize ['modifyvm',:id,'--nicpromisc3','allow-all']
  128.       end
  129.       if i === 1
  130.         leaf.vm.provision "shell", inline: $leaf01_script
  131.       end
  132.       if i === 2
  133.         leaf.vm.provision "shell", inline: $leaf02_script
  134.       end
  135.       if i === 3
  136.         leaf.vm.provision "shell", inline: $leaf03_script
  137.       end
  138.       leaf.vm.provision "shell", inline: <<-EOC
  139. chmod 777 /tmp/provision-template.sh
  140. sg vyattacfg -c /tmp/provision-template.sh
  141.       EOC
  142.     end
  143.   end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement