Repository navigation
HostPrep.ps1 v4.4.0: offer to fix the ESXi hostname before certificate regeneration - #9
Merged
Merged
Conversation
generate-certificates derives the certificate CN from the host's own configured hostname, so a host that still calls itself localhost.localdomain keeps minting the wrong CN however often it is regenerated. The script already refused to waste a reboot on that, but it left the operator to go fix the hostname by hand and re-run. Add Repair-ESXiHostname: on a mismatch, prompt Y/N, set the hostname and domain from the host list via Set-VMHostNetwork, read them back to confirm the change stuck, then continue into regeneration -- which reboots the host anyway, so the rename costs no extra reboot. Declining keeps the previous behaviour (skip regen, flag CN mismatch in the report). Hosts are never renamed silently. Found while testing against a live host. (GitHub issue #8) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A host that obtains its DNS settings from DHCP takes its hostname and domain from there as well. Set-VMHostNetwork accepts -HostName/-DomainName on such a host, reports no error, and changes nothing -- so the read-back reported a baffling "hostname still reads 'localhost' after the change". Check DnsFromDhcp before prompting: explain that ESXi ignores a hostname set while DHCP is in charge, and point at the static-DNS setting. No pointless Y/N question, and no silent no-op call. Hit on a live host: the rename appeared to succeed and did nothing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pauldiee
force-pushed
the
issue-8-fix-esxi-hostname
branch
from
July 14, 2026 13:14
9ddf3e4 to
38e4e77
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8.
Why
/sbin/generate-certificatesbuilds the certificate CN from the host's own configured hostname, not from the FQDN in the host list. A freshly imaged host that still calls itselflocalhost.localdomaintherefore keeps mintinglocalhost.localdomaincertificates no matter how often it is regenerated — and each attempt costs a reboot.The script already refused to waste that reboot, but it stopped there and left the operator to go fix the hostname by hand and re-run:
What changed
New
Repair-ESXiHostname. On a mismatch the script now offers to correct it:Set-VMHostNetwork, reads them back from the host to confirm the change stuck, then continues into regeneration. Regen reboots the host anyway, so the rename needs no reboot of its own.CN mismatchin the report.Hosts are never renamed silently — hence the prompt, matching the
-WipeDiskidiom.-DryRunreports the offer and changes nothing.Also handled: a short name in the host list (no domain to derive) is refused rather than guessed at, and a rename that throws or silently fails to apply skips regeneration instead of rebooting into the same wrong CN.
Testing
Not yet run end-to-end against a live host — the guard that motivated it was hit on a live host, but the fix path has not been.
Repair-ESXiHostnamewas exercised in isolation with PowerCLI mocked:Set-VMHostNetworkcalled withN)y)esxi01/vcf.labesxi01/mgmt.vcf.labSet-VMHostNetworkthrowsNote on versioning
Branched off
main, so this is v4.4.0 and assumes #7 (v4.3.0) merges first. If #7 is merged, I can rebase this to keep the changelog linear.🤖 Generated with Claude Code