hi, is it possible to set the hostname with cloud-...
# elemental
q
hi, is it possible to set the hostname with cloud-config and let this be the hostname which is used for the machine registration? we don't use dhcp for hostnames but also dont want to monitor servers named like m-xyz because we want to know which service has a problem from reading the servers hostname.
s
I am not sure I understand the demand here, as the hostname should be unique for machine. You could eventually set some template as defined in https://elemental.docs.rancher.com/hostname so you could use something else than the default
m-{UUID}
as a
machineName
. Also, you could attempt to define the ISO's system hostname in SeedImage cloudconfig and from then use
machineName: "${System Data/Runtime/Hostname}"
in registration to name the machine with the hostname at the time of registration.
q
yes, i am right now testing this. the demand is we want speaking hostnames like encoding-cluster-worker-1 etc. and not m-23423423-23423-4
created an image with
Copy code
apiVersion: <http://elemental.cattle.io/v1beta1|elemental.cattle.io/v1beta1>
kind: MachineRegistration
metadata:
  name: machineregistration-vmware
  namespace: fleet-default
spec:
  machineName: "${System Data/Runtime/Hostname}"
  config:
    cloud-config:
#      datasource:
#        providers:
#          - "vmware"
      runcmd:
        - hostnamectl set-hostname $(vmtoolsd --cmd "info-get guestinfo.hostname")
      users:
        - name: root
          passwd: root
    elemental:
      install:
        reboot: true
        device: /dev/sda
        debug: true
  machineInventoryLabels:
    element: cluster-3-worker
    manufacturer: "${System Information/Manufacturer}"
    productName: "${System Information/Product Name}"
    serialNumber: "${System Information/Serial Number}"
    machineUUID: "${System Information/UUID}"
    hostname: "${System Data/Runtime/Hostname"
when login to the machine the hostname is how i want it but elemental registered it with
rancher-13404
hmm it seems hostnamectl removed the link to /usr/local/etc/hostname
s
Yes this is expected because
machineName: "${System Data/Runtime/Hostname}"
just uses the hostname at the time of registration. At this stage the
hostnamectl set-hostname ...
is not yet applied. This should be applied at the cloud-config of the ISO, so it gets applied at ISO boot, this hostname should be set before registering in order to make it sticky via
machineName
.
In the seedimage spec you could have something like:
Copy code
apiVersion: <http://elemental.cattle.io/v1beta1|elemental.cattle.io/v1beta1>
kind: SeedImage
metadata:
  name: fire-img
  namespace: fleet-default
spec:
  cloud-config:
    runcmd:
      - hostnamectl set-hostname $(vmtoolsd --cmd "info-get guestinfo.hostname")
  registrationRef:
    name: <registration_resource_name>
    namespace: fleet-default
  baseImage: <iso_image_reference>
This way the ISO at boot time would set the hostname and this would be used for registering.
q
ah, i didn't know i can use cloud-config in SeedImage. will try that then. thx
awesome, this works. 👍 btw. the hostname label is now m-System-Data-Runtime-Hostname?
s
Not sure I understand the question, is it a about a weird label? The label has a typo in your machine registration, see the missing
}
to close the template variable.
q
ah right, it's a typo. thx again