nsidc / vagrant-vsphere

VMware vSphere provider for Vagrant
Other
608 stars 166 forks source link

vagant loop weird #301

Closed NA3 closed 1 year ago

NA3 commented 1 year ago
Vagrant.configure(2) do |config|

boxes = [
  # windows server 2022 : don't work for now
  #{ :name => "DC01",  :ip => "192.168.56.10", :box => "StefanScherer/windows_2022", :box_version => "2021.08.23", :os => "windows"},
  # windows server 2019
  { :name => "DC01", :hostname => "DC01",  :ip => "192.168.56.10", :box => "windows-2019-amd64", :os => "windows"},
  # windows server 2019
  { :name => "DC02", :hostname => "DC02",  :ip => "192.168.56.11", :box => "windows-2019-amd64", :os => "windows"},
  # windows server 2016
  { :name => "DC03", :hostname => "DC03", :ip => "192.168.56.12", :box => "windows-2019-amd64", :os => "windows"},
  # windows server 2019
  #{ :name => "SRV01", :ip => "192.168.56.21", :box => "StefanScherer/windows_2019", :box_version => "2020.07.17", :os => "windows"},
  # windows server 2019
  { :name => "SRV02", :hostname => "SRV02", :ip => "192.168.56.22", :box => "windows-2019-amd64", :os => "windows"},
  # windows server 2016
  { :name => "SRV03", :hostname => "SRV03", :ip => "192.168.56.23", :box => "windows-2019-amd64", :os => "windows"}
  # ELK
# { :name => "elk", :ip => "192.168.56.50", :box => "bento/ubuntu-18.04", :os => "linux",
#   :forwarded_port => [
#     {:guest => 22, :host => 2210, :id => "ssh"}
#   ]
# }
]
  config.vm.boot_timeout = 600
  config.vm.graceful_halt_timeout = 600
  VM_CPUS = 4
  VM_MEMORY_MB = 4*1024
  VM_OS_DISK_GB = 60

  boxes.each do |box|
    config.vm.define box[:name] do |cfg|
      cfg.vm.box = box[:box]
      cfg.vm.hostname = box[:name]
      # disable rdp forwarded port inherited from StefanScherer box
      cfg.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true, disabled: true
      # issues/49
      cfg.vm.synced_folder '.', '/vagrant', disabled: true
      # IP
      cfg.vm.network :private_network, ip: box[:ip]
      # OS specific
      if box[:os] == "windows"
        cfg.vm.guest = :windows
        cfg.vm.communicator = "winrm"
        cfg.vm.provision :shell, :path => "./Install-WMF3Hotfix.ps1", privileged: false
        cfg.vm.provision :shell, :path => "./ConfigureRemotingForAnsible.ps1", privileged: false
      else
        cfg.vm.communicator = "ssh"
      end
      if box.has_key?(:forwarded_port)
        # forwarded port explicit
        box[:forwarded_port] do |forwarded_port|
          cfg.vm.network :forwarded_port, guest: forwarded_port[:guest], host: forwarded_port[:host], host_ip: "127.0.0.1", id: forwarded_port[:id]
        end
      end
    end
    config.vm.provider 'vsphere' do |vsphere|
      vsphere.name = box[:name]
      vsphere.notes = "Created from #{__FILE__}"
      vsphere.memory_mb = VM_MEMORY_MB
      vsphere.cpu_count = VM_CPUS
      vsphere.user = ENV['GOVC_USERNAME']
      vsphere.password = ENV['GOVC_PASSWORD']
      vsphere.insecure = true
      vsphere.host = ENV['GOVC_HOST']
      vsphere.data_center_name = ENV['GOVC_DATACENTER']
      vsphere.compute_resource_name = ENV['GOVC_CLUSTER']
      vsphere.data_store_name = ENV['GOVC_DATASTORE']
      vsphere.template_name = ENV['VSPHERE_TEMPLATE_NAME']
      vsphere.vm_base_path = ENV['VSPHERE_VM_FOLDER']
      vsphere.vlan = ENV['VSPHERE_VLAN']
    end
  end
end

image

i don't know why all vm's got SRV03 on "target VM" all help are welcome. Regards.

NA3 commented 1 year ago

got it working

ninalihk commented 5 months ago

@NA3 Hello, I am trying to use your configuration to build a Goad laboratory, but he will report an error, can you help me? image This is my box list image this my config file image