Skip to content

Commit 75c62e1

Browse files
Fix: Remove stale Packer nameserver in RHEL-based images on OpenStack
Adds a final shell provisioner at the end of the build to remove all 'nameserver' entries from /etc/resolv.conf before finalizing RHEL-based images. This addresses a bug where RHEL/NetworkManager retains the temporary Packer build subnet nameserver (e.g., 10.0.2.3) alongside DHCP-provided ones, causing intermittent DNS resolution failures for internal domains in OpenStack. Implementation details: - A variable is introduced in packer.json.tmpl (default: false). - This variable is overridden to true in qemu-rockylinux-9.json so the cleanup runs for all RHEL-based images. - Non-RHEL builds remain unaffected. Placed after Goss validation so: - Goss runs with working DNS during build - Final image boots with only DHCP-provided nameservers - Cloud-init does not reintroduce stale nameservers Fixes #1832 Signed-off-by: Truong Hoang Phu Loc <[email protected]>
1 parent 0279249 commit 75c62e1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

images/capi/packer/qemu/packer.json.tmpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,23 @@
152152
"kubernetes_version": "{{user `kubernetes_semver` | replace \"v\" \"\" 1}}"
153153
},
154154
"version": "{{user `goss_version`}}"
155+
},
156+
{
157+
"type": "shell",
158+
"environment_vars": [
159+
"REMOVE_NAMESERVER={{user `remove_nameserver`}}"
160+
],
161+
"inline": [
162+
"if [ \"$REMOVE_NAMESERVER\" = \"true\" ]; then",
163+
" cat /etc/resolv.conf",
164+
" echo 'Removing nameserver from resolv.conf...'",
165+
" sudo sed -i '/^nameserver/d' /etc/resolv.conf",
166+
" echo 'Removing stale nameserver is done, checking the current content of /etc/resolv.conf...'",
167+
" cat /etc/resolv.conf",
168+
"else",
169+
" echo 'Skipping nameserver cleanup.'",
170+
"fi"
171+
]
155172
}
156173
],
157174
"variables": {

images/capi/packer/qemu/qemu-rockylinux-9.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
"iso_url": "https://dl.rockylinux.org/vault/rocky/9.4/isos/x86_64/Rocky-9.4-x86_64-minimal.iso",
1414
"os_display_name": "RockyLinux 9",
1515
"redhat_epel_rpm": "https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm",
16+
"remove_nameserver": "true",
1617
"shutdown_command": "/sbin/halt -h -p"
1718
}

0 commit comments

Comments
 (0)