From f8f689bc99504165a22f8e7e3aca3fdf43579185 Mon Sep 17 00:00:00 2001 From: MatthewHink Date: Thu, 27 Jan 2022 17:36:27 -0500 Subject: [PATCH] Fix network name in /etc/hosts. Fixes #247. For hosts with ip addresses, the hosts file entry should be: - - For the default network interface, the node name is included as well: - - --- etc/hosts.tmpl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/etc/hosts.tmpl b/etc/hosts.tmpl index feedb4ca..1754ff01 100644 --- a/etc/hosts.tmpl +++ b/etc/hosts.tmpl @@ -1,15 +1,15 @@ {{$.PrevHostFile}}# Do not edit after this line - these host entries are maintained by warewulf -{{range $node := $.AllNodes}} +{{range $node := $.AllNodes}} {{/* for each node */}} # Entry for {{$node.Id.Get}} -{{- range $devname, $netdev := $node.NetDevs}} -{{- if $netdev.Ipaddr.Defined}} -{{- if $netdev.Default.GetB}} -{{$netdev.Ipaddr.Get}} {{$node.Id.Get}} +{{- range $devname, $netdev := $node.NetDevs}} {{/* for each network device on the node */}} +{{- if $netdev.Ipaddr.Defined}} {{/* if we have an ip address on this network device */}} +{{- if $netdev.Default.GetB}} {{/* emit the node name as hostname if this is the default */}} +{{$netdev.Ipaddr.Get}} {{$node.Id.Get}} {{$node.Id.Get}}-{{$devname}} {{$node.Id.Get}}-{{$netdev.Device.Get}} {{- else}} -{{$netdev.Ipaddr.Get}} {{$node.Id.Get}}-{{$devname}} -{{- end}} -{{- end}} -{{- end}} -{{end}} +{{$netdev.Ipaddr.Get}} {{$node.Id.Get}}-{{$devname}} {{$node.Id.Get}}-{{$netdev.Device.Get}} +{{- end}} {{/* end if default */}} +{{- end}} {{/* end if ip */}} +{{- end}} {{/* end for each network device */}} +{{end}} {{/* end for each node */}}