Packer + autoinstall gets new IP several times in install process
I am using Packer to build ubuntu 20.04 templates in a vsphere environment. It works about 50% of the time, the rest it fails because during the boot/install/reboot phases, the IP changes 3 different times and Packer can't keep up.
DHCP is handled by an upstream Juniper SRX router. I've got the `dhcp_identifier: mac` option set, as well as have used a late-command to add it to the 00-installer netplan, but it is not reliable. I've also tested feeding a specified mac into the packer configs and setting a static IP assignment in the SRX.
The DUID/UUID vs MAC thing seems to be the root of the issue, but I'm not sure what can be done about it. Even with a predefined MAC and a static address set for it, I get different IPs, even though in the SRX arp table I see the correct MAC with the incorrect IP.
Here's the user-data I'm passing, I've sanitized it a little but otherwise it's exactly what I'm sending:
```
#cloud-config
autoinstall:
update: no
identity:
hostname: ubuntu2004template
password: 'supersecurehash'
realname: Admin
username: admin
version: 1
ssh:
install-server: yes
locale: en_US
keyboard:
layout: us
## for static IP build on vmware/vcenter
# network:
# network:
# version: 2
# ethernets:
# enwild:
# match:
# name: en*
# addresses: [10.1.1.238/24]
# gateway4: 10.1.1.1
# nameservers:
# addresses:
# - 10.1.1.6
# network:
# network:
# version: 2
# ethernets:
# ens160:
# dhcp4: true
# dhcp6: false
# dhcp-identifier: mac
## for local vmware builds
# network:
# network:
# version: 2
# ethernets:
# ens33:
# dhcp4: true
## matching eth or en*
network:
network:
version: 2
renderer: networkd
ethernets:
eth0:
match:
dhcp4: true
# otherif:
# match:
# name:eth*
# dhcp4: true
# dhcp-identifier: mac
storage:
config:
- grub_device: true
id: disk-sda
path: /dev/sda
ptable: gpt
type: disk
wipe: superblock-
- device: disk-sda
flag: bios_grub
id: partition-1
number: 1
size: 1048576
type: partition
- device: disk-sda
wipe: superblock
flag: ''
number: 2
preserve: false
grub_device: false
type: partition
id: partition-2
size: 1073741824
- fstype: ext4
volume: partition-2
preserve: false
type: format
id: format-11
- device: disk-sda
size: -1
wipe: superblock
flag: ''
number: 3
preserve: false
grub_device: false
type: partition
id: partition-3
- name: ubuntu-vg
devices: [partition-3]
preserve: false
type: lvm_volgroup
id: lvm_volgroup-3
- name: root
volgroup: lvm_volgroup-3
size: 35%
preserve: false
type: lvm_partition
id: lvm_partition-9
- name: swap
volgroup: lvm_volgroup-3
size: 5%
preserve: false
type: lvm_partition
id: lvm_partition-10
- fstype: swap
volume: lvm_partition-10
preserve: false
type: format
id: format-13
- device: format-13
path: ''
type: mount
id: mount-13
- name: tmp
volgroup: lvm_volgroup-3
size: 10%
preserve: false
type: lvm_partition
id: lvm_partition-11
- fstype: ext4
volume: lvm_partition-11
preserve: false
type: format
id: format-14
- name: var
volgroup: lvm_volgroup-3
size: 10%
preserve: false
type: lvm_partition
id: lvm_partition-12
- fstype: ext4
volume: lvm_partition-12
preserve: false
type: format
id: format-15
- name: var_tmp
volgroup: lvm_volgroup-3
size: 5%
preserve: false
type: lvm_partition
id: lvm_partition-13
- fstype: ext4
volume: lvm_partition-13
preserve: false
type: format
id: format-16
- name: log
volgroup: lvm_volgroup-3
size: 10%
preserve: false
type: lvm_partition
id: lvm_partition-14
- fstype: ext4
volume: lvm_partition-14
preserve: false
type: format
id: format-17
- name: audit
volgroup: lvm_volgroup-3
size: 10%
preserve: false
type: lvm_partition
id: lvm_partition-15
- fstype: ext4
volume: lvm_partition-15
preserve: false
type: format
id: format-18
- name: home
volgroup: lvm_volgroup-3
size: 10%
preserve: false
type: lvm_partition
id: lvm_partition-16
- fstype: ext4
volume: lvm_partition-16
preserve: false
type: format
id: format-19
- fstype: ext4
volume: lvm_partition-9
preserve: false
type: format
id: format-21
- device: format-21
path: /
type: mount
id: mount-21
- device: format-11
path: /boot
type: mount
id: mount-11
- device: format-14
path: /tmp
type: mount
id: mount-14
options: 'nodev,
- device: format-15
path: /var
type: mount
id: mount-15
- device: format-16
path: /var/tmp
type: mount
id: mount-16
options: 'nodev,
- device: format-17
path: /var/log
type: mount
id: mount-17
- device: format-18
path: /var/log/audit
type: mount
id: mount-18
- device: format-19
path: /home
type: mount
id: mount-19
options: 'nodev'
packages:
- open-vm-tools
- ansible
- wget
user-data:
timezone: America/Chicago
late-commands:
- "echo 'Defaults:admin !requiretty' > /target/
- "echo 'admin ALL=(ALL) NOPASSWD: ALL' >> /target/
- "chmod 440 /target/
- "sed -i -e 's/^# HOME=\\
- "sed -i -e 's/^DHOME=
- "mkdir -p /target/
- "echo 'admin ALL=(ALL) NOPASSWD: ALL' >> /target/
- 'sed -i "s/^#Port 22/Port 22/g" /target/
- 'sed -i "/^Port 22/a Port 1981" /target/
# - 'sed -i "s/dhcp4: true/&\n dhcp-identifier: mac/" /target/
# - "useradd -m -d /target/
```
Here's an example run where the IP changes multiple times in a single run:
```
show dhcp server binding routing-instance trust-vr
IP address Session Id Hardware address Expires State Interface
10.20.30.226 1116 00:00:00:00:5a:6e 82585 BOUND xe-6/0/1.99
10.20.30.241 1123 00:00:00:00:5a:6e 83605 BOUND xe-6/0/1.99
10.20.30.231 1126 00:00:00:00:5a:6e 85473 BOUND xe-6/0/1.99
10.20.30.233 1128 00:00:00:00:5a:6e 85875 BOUND xe-6/0/1.99
```
In that case, the .241 was the statically assigned DHCP address to the MAC, and though I sanitized them, the MACs were all the same.
I know there's a boot command option of `ip=dhcp`, is there a similar option setting the identifier to MAC? In the user-data above, the commented out sections are attempts with different options. The only reliable method has been a static IP not using dhcp, but that address gets copied to any VMs built with the template, so not ideal.
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Ubuntu Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Brantley Padgett for more information if necessary.