diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote index 64fff7ad..182d37ae 100755 --- a/cdist/conf/type/__hostname/gencode-remote +++ b/cdist/conf/type/__hostname/gencode-remote @@ -78,6 +78,11 @@ in echo "printf '%s\\n' '$name_should' > /etc/hostname" echo "hostname -F /etc/hostname" ;; + gentoo) + # NOTE: Writing the hostname to file is done in the manifest for OpenRC. + # For systemd hostnamectl should take care of that. + echo "hostname '$name_should'" + ;; macosx) echo "scutil --set HostName '$name_should'" ;; @@ -87,7 +92,7 @@ in echo "printf '%s\\n' '$name_should' > /etc/HOSTNAME" echo 'hostname -F /etc/HOSTNAME' ;; - centos|fedora|freebsd|gentoo|netbsd|openbsd|redhat|scientific) + centos|fedora|freebsd|netbsd|openbsd|redhat|scientific) # NOTE: Writing the hostname to file is done in the manifest. echo "hostname '$name_should'" ;; diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 0ffd7678..58034a19 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -52,18 +52,28 @@ in : ;; centos|fedora|redhat|scientific) - __key_value sysconfig-hostname \ - --file /etc/sysconfig/network \ - --delimiter '=' --exact_delimiter \ - --key HOSTNAME \ - --value "\"$name_should\"" + if test -z "$(cat "$__object/explorer/has_hostnamectl")" + then + # Only write to /etc/sysconfig/network on non-systemd versions. + # On systemd-based versions this entry is ignored. + __key_value sysconfig-hostname \ + --file /etc/sysconfig/network \ + --delimiter '=' --exact_delimiter \ + --key HOSTNAME \ + --value "\"$name_should\"" + fi ;; gentoo) - __key_value confd-hostname \ - --file /etc/conf.d/hostname \ - --delimiter '=' --exact_delimiter \ - --key 'hostname' \ - --value "\"$name_should\"" + if test -z "$(cat "$__object/explorer/has_hostnamectl")" + then + # Only write to /etc/conf.d/hostname on OpenRC-based installations. + # On systemd use hostnamectl(1) in gencode-remote. + __key_value confd-hostname \ + --file /etc/conf.d/hostname \ + --delimiter '=' --exact_delimiter \ + --key 'hostname' \ + --value "\"$name_should\"" + fi ;; freebsd) __key_value rcconf-hostname \