dev4vater / vater

11 stars 5 forks source link

Set static IP addresses in Packer builds from `group_vars`. #111

Closed uwardlaw closed 2 years ago

uwardlaw commented 2 years ago

When creating templates their IP addresses need to be set by Packer. Because Packer communicates with the templates via routable network service, the templates need to be placed a on staging network with the control VM.

Once the VM is configured, Terraform will not reattach the staging adapter to a network.

Future configuration via Ansible will be done by interfacing with the Vsphere API.

comeste10 commented 2 years ago

So we confirmed that Packer isn't capable of communicating with the templates via the vSphere API?

@rylagek do you know where this leaves us wrt the chicken and egg problem with Windows XP and getting WinRM installed? Should we stick with just newer versions of Windows?

uwardlaw commented 2 years ago

I wouldn't say we confirmed it, but what we did find is that even if we tell Packer to upload and start a script that changes IPs, which executes successfully, Packer will hang because it loses shell connection and can't reconnect to a device not on it's subnet. Packer expects to see the script completed successfully before reporting the template is built and converting it.

I didn't upload my notes yet on the issue, but will when we get in Monday.

WinRM works fine as I recall.

uwardlaw commented 2 years ago

I thought this method would work, but it's become obvious it probably won't. There's not a good way to know what physical adapter (e.g. SPNT-DEV-LAN) is associated with which logical adapter (e.g. eth0 192.168.100.1). So if there are 5-6 adapters, and we set their IPs, when the template is deployed we have no guarantee the correct logical to physical adapters are associated. This again brings us to using Terraform to set IPs.

uwardlaw commented 2 years ago

In #71 we noted the issue of using the customization block. The Terraform documentation specifies that different operating systems will have different experiences with this.

Further documentation says,

These settings, which should be specified in nested network_interface blocks within customize, configure network interfaces on a per-interface basis and are matched up to network_interface devices in the order they are declared.
uwardlaw commented 2 years ago

After more testing, it's clear we will have to treat each operating system different. The customization block failed for Vyos because the customization block uses VMWare guest OS customization, which Vyos is not compatible with.

The solution for Vyos was to continue using the inline shell but keep a connection open. We keep the connection open by configuring an additional interface with DHCP via the boot command. This should be the last interface for the device.

For the core_router the DHCP interface is eth2 and we configure eth0 and eth1 for different things needed in the lab (connections to other routers). Then, when Terraform deploys the router, it configures interface in order per their docs:

Network interfaces are managed by adding an instance of the network_interface block.

Interfaces are assigned to devices in the specific order they are declared. This has different implications for different operating systems.

We only create interfaces for eth0 and eth1, so when Vyos boots, it discards eth2 confgurations.

The method of using an additional interface for Packer setup seems to be pretty reliable, but will require testing on a per OS basis. @rylagek

The only thing left on this is to make the IP addresses configurable via group_vars

marissaeinhorn commented 2 years ago

Not required for RANS implementation or intermediate solution