Last active
February 10, 2021 17:45
-
-
Save darkmuggle/33541047543cb86c6b8d4a5f4e562fb9 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/templates/common/vsphere/files/vsphere-hostname.yaml b/templates/common/vsphere/files/vsphere-hostname.yaml | |
index b3dfef52..e4be8220 100644 | |
--- a/templates/common/vsphere/files/vsphere-hostname.yaml | |
+++ b/templates/common/vsphere/files/vsphere-hostname.yaml | |
@@ -5,6 +5,9 @@ contents: | |
#!/usr/bin/env bash | |
set -e | |
+ # only run if the hostname is not set | |
+ test -f /etc/hostname && exit 0 || : | |
+ | |
if vm_name=$(/bin/vmtoolsd --cmd 'info-get guestinfo.hostname'); then | |
- /usr/bin/hostnamectl --transient set-hostname ${vm_name} | |
+ /usr/bin/hostnamectl set-hostname --static ${vm_name} | |
fi | |
diff --git a/templates/common/vsphere/units/vsphere-hostname.service.yaml b/templates/common/vsphere/units/vsphere-hostname.service.yaml | |
index 3dbaafcf..a2e331cc 100644 | |
--- a/templates/common/vsphere/units/vsphere-hostname.service.yaml | |
+++ b/templates/common/vsphere/units/vsphere-hostname.service.yaml | |
@@ -3,7 +3,14 @@ enabled: true | |
contents: | | |
[Unit] | |
Description=vSphere hostname | |
+ Requires=vmtoolsd.service | |
After=vmtoolsd.service | |
+ | |
+ # Only run on first boot and only if the host does not have a name yet | |
+ ConditionPathExists=/etc/ignition-machine-config-encapsulated.json | |
+ ConditionPathExists=!/etc/hostname | |
+ ConditionVirtualization=vmware | |
+ | |
Before=kubelet.service | |
Before=node-valid-hostname.service | |
Before=NetworkManager.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment