Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full support for vmware_esxi provider #210

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ This lab use free windows VM only (180 days). After that delay enter a license o
- For linux users check dependencies installation before install :

```
./goad -t check -l <LAB> -p <PROVIDER> -m <ANSIBLE_RUN_METHOD>
./goad.sh -t check -l <LAB> -p <PROVIDER> -m <ANSIBLE_RUN_METHOD>
```

- LAB: lab must be one of the following (folder in ad/)
Expand All @@ -97,7 +97,7 @@ This lab use free windows VM only (180 days). After that delay enter a license o
- Launch all the install (vagrant or terraform) vms creation followed by ansible provisioning :

```
./goad -t install -l <LAB> -p <PROVIDER> -m <ANSIBLE_RUN_METHOD>
./goad.sh -t install -l <LAB> -p <PROVIDER> -m <ANSIBLE_RUN_METHOD>
```

- The goad install will run all the ansible playbook one by one with a failover to restart the ansible playbook if something goes wrong (sometimes vms or playbook hit timeout so this will restart the playbook automatically)
Expand Down
6 changes: 6 additions & 0 deletions ad/GOAD-Light/providers/vmware_esxi/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export GOAD_VAGRANT_ESXIHOSTNAME='10.10.10.10'
export GOAD_VAGRANT_ESXIUSERNAME='root'
export GOAD_VAGRANT_ESXIPASSWORD='password'
export GOAD_VAGRANT_ESXINETNAT='VM Network'
export GOAD_VAGRANT_ESXINETDOM='GOAD-LAN'
export GOAD_VAGRANT_ESXISTORE='datastore1'
80 changes: 80 additions & 0 deletions ad/GOAD-Light/providers/vmware_esxi/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Vagrant.configure("2") do |config|

# Uncomment this depending on the provider you want to use
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_esxi'

# auto-load .env if vagrant-env installed
if Vagrant.has_plugin?("vagrant-env") then
config.env.enable # Enable vagrant-env(.env)
end

boxes = [
# windows server 2019
{ :name => "GOAD-DC01", :ip => "192.168.56.10", :box => "StefanScherer/windows_2019", :box_version => "2021.05.15", :os => "windows"},
# windows server 2019
{ :name => "GOAD-DC02", :ip => "192.168.56.11", :box => "StefanScherer/windows_2019", :box_version => "2021.05.15", :os => "windows"},
# windows server 2019
{ :name => "GOAD-SRV02", :ip => "192.168.56.22", :box => "StefanScherer/windows_2019", :box_version => "2021.05.15", :os => "windows"},
]

# disable rdp forwarded port inherited from StefanScherer box
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true, disabled: true

# no autoupdate if vagrant-vbguest is installed
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end

config.vm.boot_timeout = 600
config.vm.graceful_halt_timeout = 600
config.winrm.retry_limit = 30
config.winrm.retry_delay = 10

boxes.each do |box|
config.vm.define box[:name] do |target|
# BOX
target.vm.provider :vmware_esxi do |v|
v.esxi_hostname = ENV['GOAD_VAGRANT_ESXIHOSTNAME']
v.esxi_username = ENV['GOAD_VAGRANT_ESXIUSERNAME']
v.esxi_password = ENV['GOAD_VAGRANT_ESXIPASSWORD']
v.esxi_virtual_network = [ ENV['GOAD_VAGRANT_ESXINETNAT'], ENV['GOAD_VAGRANT_ESXINETDOM'] ]
v.guest_numvcpus = '4'
v.guest_memsize = '6000'
v.guest_name = box[:name]
v.esxi_disk_store = ENV['GOAD_VAGRANT_ESXISTORE']
end
target.vm.box_download_insecure = box[:box]
target.vm.box = box[:box]
if box.has_key?(:box_version)
target.vm.box_version = box[:box_version]
end

# issues/49
target.vm.synced_folder '.', '/vagrant', disabled: true

# OS specific
if box[:os] == "windows"
target.vm.guest = :windows
target.vm.communicator = "winrm"
target.vm.provision :shell, :path => "../../../../vagrant/Install-WMF3Hotfix.ps1", privileged: false
target.vm.provision :shell, :path => "../../../../vagrant/ConfigureRemotingForAnsible.ps1", privileged: false

# fix ip for vmware
if ENV['VAGRANT_DEFAULT_PROVIDER'] == "vmware_esxi"
target.vm.provision :shell, :path => "../../../../vagrant/fix_ip.ps1", privileged: false, args: box[:ip]
end

else
target.vm.communicator = "ssh"
end

if box.has_key?(:forwarded_port)
# forwarded port explicit
box[:forwarded_port] do |forwarded_port|
target.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
end
end
39 changes: 39 additions & 0 deletions ad/GOAD-Light/providers/vmware_esxi/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[default]
; Note: ansible_host *MUST* be an IPv4 address or setting things like DNS
; servers will break.
; ------------------------------------------------
; sevenkingdoms.local
; ------------------------------------------------
dc01 ansible_host=192.168.56.10 dns_domain=dc01 dict_key=dc01
; ------------------------------------------------
; north.sevenkingdoms.local
; ------------------------------------------------
dc02 ansible_host=192.168.56.11 dns_domain=dc01 dict_key=dc02
srv02 ansible_host=192.168.56.22 dns_domain=dc02 dict_key=srv02

[all:vars]
; domain_name : folder inside ad/
domain_name=GOAD-Light

force_dns_server=no
dns_server=x.x.x.x
two_adapters=yes

; adapter created by vagrant and vmware (uncomment if you use vmware)
nat_adapter=Ethernet0
domain_adapter=Ethernet1

; winrm connection (windows)
ansible_user=vagrant
ansible_password=vagrant
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_winrm_operation_timeout_sec=400
ansible_winrm_read_timeout_sec=500
# ansible_winrm_transport=basic
# ansible_port=5985

; proxy settings (the lab need internet for some install, if you are behind a proxy you should set the proxy here)
enable_http_proxy=no
ad_http_proxy=http://x.x.x.x:xxxx
ad_https_proxy=http://x.x.x.x:xxxx
6 changes: 6 additions & 0 deletions ad/GOAD/providers/vmware_esxi/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export GOAD_VAGRANT_ESXIHOSTNAME='10.10.10.10'
export GOAD_VAGRANT_ESXIUSERNAME='root'
export GOAD_VAGRANT_ESXIPASSWORD='password'
export GOAD_VAGRANT_ESXINETNAT='VM Network'
export GOAD_VAGRANT_ESXINETDOM='GOAD-LAN'
export GOAD_VAGRANT_ESXISTORE='datastore1'
91 changes: 91 additions & 0 deletions ad/GOAD/providers/vmware_esxi/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Vagrant.configure("2") do |config|

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_esxi'

# auto-load .env if vagrant-env installed
if Vagrant.has_plugin?("vagrant-env") then
config.env.enable # Enable vagrant-env(.env)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the vagrant-env plugin is necessarily installed if you go through goad.sh and that the configuration will be missing if you go through vagrant up without the vagrant-env plugin, wouldn't it be better to replace this condition with an error directly if the plugin isn't present? (if this is the case, you'd have to make the change to the other files too)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be, though it's not strictly necessary, I usually sourced the env file manually during testing, but made them compatible with the vagrant-env plugin, if env file is not modified and present in environment provisioning will fail anyhow. Maybe this needs to be documented more thoroughly?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Thinking clearer error handling will suffice. Also will add this to docs.

boxes = [
# windows server 2019
{ :name => "GOAD-DC01", :ip => "192.168.56.10", :box => "StefanScherer/windows_2019", :box_version => "2021.05.15", :os => "windows"},
# windows server 2019
{ :name => "GOAD-DC02", :ip => "192.168.56.11", :box => "StefanScherer/windows_2019", :box_version => "2021.05.15", :os => "windows"},
# windows server 2016
{ :name => "GOAD-DC03", :ip => "192.168.56.12", :box => "StefanScherer/windows_2016", :box_version => "2017.12.14", :os => "windows"},
# windows server 2019
{ :name => "GOAD-SRV02", :ip => "192.168.56.22", :box => "StefanScherer/windows_2019", :box_version => "2020.07.17", :os => "windows"},
# windows server 2016
{ :name => "GOAD-SRV03", :ip => "192.168.56.23", :box => "StefanScherer/windows_2016", :box_version => "2019.02.14", :os => "windows"}
]

if ENV.has_key?('GOAD_VAGRANT_OPTIONS') and ENV['GOAD_VAGRANT_OPTIONS'].include? "elk"
boxes.append(
{ :name => "GOAD-ELK", :ip => "192.168.56.50", :box => "bento/ubuntu-18.04", :os => "linux", :forwarded_port => [
{:guest => 22, :host => 2210, :id => "ssh"} ]
}
)
end

# disable rdp forwarded port inherited from StefanScherer box
config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct: true, disabled: true

# no autoupdate if vagrant-vbguest is installed
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end

config.vm.boot_timeout = 600
config.vm.graceful_halt_timeout = 600
config.winrm.retry_limit = 30
config.winrm.retry_delay = 10

boxes.each do |box|
config.vm.define box[:name] do |target|
# BOX
target.vm.provider :vmware_esxi do |v|
v.esxi_hostname = ENV['GOAD_VAGRANT_ESXIHOSTNAME']
v.esxi_username = ENV['GOAD_VAGRANT_ESXIUSERNAME']
v.esxi_password = ENV['GOAD_VAGRANT_ESXIPASSWORD']
v.esxi_virtual_network = [ ENV['GOAD_VAGRANT_ESXINETNAT'], ENV['GOAD_VAGRANT_ESXINETDOM'] ]
v.guest_numvcpus = '4'
v.guest_memsize = '6000'
v.guest_name = box[:name]
v.esxi_disk_store = ENV['GOAD_VAGRANT_ESXISTORE']
end
target.vm.box_download_insecure = box[:box]
target.vm.box = box[:box]
if box.has_key?(:box_version)
target.vm.box_version = box[:box_version]
end

# issues/49
target.vm.synced_folder '.', '/vagrant', disabled: true

# OS specific
if box[:os] == "windows"
target.vm.guest = :windows
target.vm.communicator = "winrm"
target.vm.provision :shell, :path => "../../../../vagrant/Install-WMF3Hotfix.ps1", privileged: false
target.vm.provision :shell, :path => "../../../../vagrant/ConfigureRemotingForAnsible.ps1", privileged: false

# fix ip for vmware
if ENV['VAGRANT_DEFAULT_PROVIDER'] == "vmware_esxi"
target.vm.provision :shell, :path => "../../../../vagrant/fix_ip.ps1", privileged: false, args: box[:ip]
end

else
target.vm.communicator = "ssh"
end

if box.has_key?(:forwarded_port)
# forwarded port explicit
box[:forwarded_port] do |forwarded_port|
target.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
end
end
57 changes: 57 additions & 0 deletions ad/GOAD/providers/vmware_esxi/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[default]
; Note: ansible_host *MUST* be an IPv4 address or setting things like DNS
; servers will break.
; ------------------------------------------------
; sevenkingdoms.local
; ------------------------------------------------
dc01 ansible_host=192.168.56.10 dns_domain=dc01 dict_key=dc01
;ws01 ansible_host=192.168.56.30 dns_domain=dc01 dict_key=ws01
; ------------------------------------------------
; north.sevenkingdoms.local
; ------------------------------------------------
dc02 ansible_host=192.168.56.11 dns_domain=dc01 dict_key=dc02
srv02 ansible_host=192.168.56.22 dns_domain=dc02 dict_key=srv02
; ------------------------------------------------
; essos.local
; ------------------------------------------------
dc03 ansible_host=192.168.56.12 dns_domain=dc03 dict_key=dc03
srv03 ansible_host=192.168.56.23 dns_domain=dc03 dict_key=srv03
; ------------------------------------------------
; Other
; ------------------------------------------------
elk ansible_host=192.168.56.50 ansible_connection=ssh

[all:vars]
; domain_name : folder inside ad/
domain_name=GOAD

force_dns_server=no
dns_server=x.x.x.x
two_adapters=yes

; adapter created by vagrant and vmware (uncomment if you use vmware)
nat_adapter=Ethernet0
domain_adapter=Ethernet1

; winrm connection (windows)
ansible_user=vagrant
ansible_password=vagrant
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_winrm_operation_timeout_sec=400
ansible_winrm_read_timeout_sec=500
# ansible_winrm_transport=basic
# ansible_port=5985

; proxy settings (the lab need internet for some install, if you are behind a proxy you should set the proxy here)
enable_http_proxy=no
ad_http_proxy=http://x.x.x.x:xxxx
ad_https_proxy=http://x.x.x.x:xxxx

[elk_server:vars]
; ssh connection (linux)
ansible_ssh_user=vagrant
ansible_ssh_private_key_file=./.vagrant/machines/elk/virtualbox/private_key
ansible_ssh_port=22
ansible_ssh_common_args='-o StrictHostKeyChecking=no'

6 changes: 6 additions & 0 deletions ad/NHA/providers/vmware_esxi/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export GOAD_VAGRANT_ESXIHOSTNAME='10.10.10.10'
export GOAD_VAGRANT_ESXIUSERNAME='root'
export GOAD_VAGRANT_ESXIPASSWORD='password'
export GOAD_VAGRANT_ESXINETNAT='VM Network'
export GOAD_VAGRANT_ESXINETDOM='GOAD-LAN'
export GOAD_VAGRANT_ESXISTORE='datastore1'
80 changes: 80 additions & 0 deletions ad/NHA/providers/vmware_esxi/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Vagrant.configure("2") do |config|

# Uncomment this depending on the provider you want to use
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_esxi'

# auto-load .env if vagrant-env installed
if Vagrant.has_plugin?("vagrant-env") then
config.env.enable # Enable vagrant-env(.env)
end

boxes = [
{ :name => "NHA-DC01", :ip => "192.168.58.10", :box => "mayfly/windows_server2019", :os => "windows"},
{ :name => "NHA-DC02", :ip => "192.168.58.20", :box => "mayfly/windows_server2019", :os => "windows"},
{ :name => "NHA-SRV01", :ip => "192.168.58.21", :box => "mayfly/windows_server2019", :os => "windows"},
{ :name => "NHA-SRV02", :ip => "192.168.58.22", :box => "mayfly/windows_server2019", :os => "windows"},
{ :name => "NHA-SRV03", :ip => "192.168.58.23", :box => "mayfly/windows_server2019", :os => "windows"}
]

# disable forwarded port
config.vm.network "forwarded_port", guest: 3389, host: 3389, id: 'rdp', auto_correct: true, disabled: true
config.vm.network "forwarded_port", guest: 22, host: 2222, id: 'ssh', auto_correct: true, disabled: true

# no autoupdate if vagrant-vbguest is installed
if Vagrant.has_plugin?("vagrant-vbguest") then
config.vbguest.auto_update = false
end

config.vm.boot_timeout = 600
config.vm.graceful_halt_timeout = 600
config.winrm.retry_limit = 30
config.winrm.retry_delay = 10

boxes.each do |box|
config.vm.define box[:name] do |target|
# BOX
target.vm.provider :vmware_esxi do |v|
v.esxi_hostname = ENV['GOAD_VAGRANT_ESXIHOSTNAME']
v.esxi_username = ENV['GOAD_VAGRANT_ESXIUSERNAME']
v.esxi_password = ENV['GOAD_VAGRANT_ESXIPASSWORD']
v.esxi_virtual_network = [ ENV['GOAD_VAGRANT_ESXINETNAT'], ENV['GOAD_VAGRANT_ESXINETDOM'] ]
v.guest_numvcpus = '4'
v.guest_memsize = '6000'
v.guest_name = box[:name]
v.esxi_disk_store = ENV['GOAD_VAGRANT_ESXISTORE']
end
target.vm.box_download_insecure = box[:box]
target.vm.box = box[:box]
if box.has_key?(:box_version)
target.vm.box_version = box[:box_version]
end

# issues/49
target.vm.synced_folder '.', '/vagrant', disabled: true

# OS specific
if box[:os] == "windows"
target.vm.guest = :windows
target.vm.communicator = "winrm"
target.vm.provision :shell, :path => "../../../../vagrant/Install-WMF3Hotfix.ps1", privileged: false
target.vm.provision :shell, :path => "../../../../vagrant/ConfigureRemotingForAnsible.ps1", privileged: false

# fix ip for vmware
if ENV['VAGRANT_DEFAULT_PROVIDER'] == "vmware_esxi"
target.vm.provision :shell, :path => "../../../../vagrant/fix_ip.ps1", privileged: false, args: box[:ip]
end

else
target.vm.communicator = "ssh"
end

if box.has_key?(:forwarded_port)
# forwarded port explicit
box[:forwarded_port] do |forwarded_port|
target.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
end
end
Loading