Vagrantfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. Vagrant.configure("2") do |config|
  2. # Configuración general de las maquinas
  3. config.vm.provider "virtualbox" do |v|
  4. v.linked_clone = true
  5. # v.synced_folder ".", "/vagrant", disabled: true # Deshabilitar sincronización de carpetas
  6. v.customize ["modifyvm", :id, "--groups", "/lab1"] # Crear todas las maquinas agrupadas en "lab1"
  7. v.customize ["modifyvm", :id, "--pagefusion", "on"] # Habilitar la compartición de paginas de memoria entre maquinas
  8. end
  9. (1..2).each do |j|
  10. ##################################
  11. # Creación de los routers cisco
  12. ##################################
  13. config.vbguest.auto_update = false # Necesario por no existir vbgest para los routers
  14. config.ssh.insert_key = false # Necesario para evitar errores de autenticacion
  15. config.vm.define "router_#{j}" do |router|
  16. router.vbguest.auto_update = false
  17. router.vm.box = "pulitux/csr1kv"
  18. router.vm.box_version = "17.03.04"
  19. router.vm.hostname = "router#{j}"
  20. router.vm.network "private_network", virtualbox__intnet: "red_#{j}", ip: "10.1.#{j}.1", auto_config: false
  21. router.vm.network "private_network", virtualbox__intnet: "red_externa", ip: "10.0.1.#{j}", auto_config: false
  22. router.vm.provider "virtualbox" do |vb|
  23. vb.name = "router_#{j}"
  24. vb.memory = "2048"
  25. end
  26. if j == 2 # Configurar todas tras crear el último router
  27. router.vm.provision "routers", type: :ansible do |ansible|
  28. ansible.limit = "routers"
  29. ansible.playbook = "provision/routers.yml"
  30. ansible.groups = {
  31. "routers" => ["router_1", "router_2"]
  32. }
  33. end
  34. end
  35. end
  36. ################################################
  37. # Creación de las máquinas Workstations Ubuntu
  38. ################################################
  39. config.vm.define "workstation_#{j}" do |workstation|
  40. # workstation.vbguest.auto_update = true
  41. workstation.vm.box = "ubuntu/jammy64"
  42. workstation.vm.hostname = "workstation#{j}"
  43. workstation.vm.network "private_network", ip: "10.1.#{j}.100"
  44. workstation.vm.provider "virtualbox" do |vb|
  45. vb.name = "workstation_#{j}"
  46. vb.memory = "2048"
  47. end
  48. if j == 2 # Configurar todas tras crear la última workstation
  49. workstation.vm.provision "workstations", type: :ansible do |ansible|
  50. ansible.limit = "workstations"
  51. ansible.playbook = "provision/workstations.yml"
  52. ansible.groups = {
  53. "workstations" => ["workstation_1", "workstation_2"]
  54. }
  55. end
  56. end
  57. end
  58. ####################################################
  59. # Creación de las máquinas servers Ubuntu
  60. ####################################################
  61. (1..2).each do |i|
  62. config.vm.define "server_#{j}_#{i}" do |server|
  63. server.vm.box = "ubuntu/jammy64"
  64. server.vm.hostname = "server#{j}#{i}"
  65. server.vm.network "private_network", ip: "10.1.#{j}.10#{i}" #, auto_config: false
  66. server.vm.provider "virtualbox" do |vb|
  67. vb.memory ="512"
  68. vb.name = "server_#{j}_#{i}"
  69. end
  70. if j == 2 and i == 2 # Ejecutar tras crear el último server
  71. server.vm.provision "servers", type: :ansible do |ansible|
  72. ansible.limit = "servers"
  73. ansible.playbook = "provision/servers.yml"
  74. ansible.groups = {
  75. "servers" => ["server_[1:2]_[1:2]"]
  76. }
  77. end
  78. # Ejecutar la configuración de todos los computadores
  79. server.vm.provision :ansible, after: "servers" do |ansible|
  80. ansible.limit = "computers"
  81. ansible.playbook = "provision/computers.yml"
  82. ansible.groups = {
  83. "workstations" => ["workstation_1", "workstation_2"],
  84. "servers" => ["server_[1:2]_[1:2]"],
  85. "computers:children" => ["workstations", "servers"]
  86. }
  87. end
  88. end
  89. end
  90. end
  91. end
  92. end