]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Changing network snippets to use hostnamectl to change the hostname.
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 31 Oct 2023 12:39:46 +0000 (13:39 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 31 Oct 2023 12:39:46 +0000 (13:39 +0100)
etc/cobbler-distros.d/rhel-9.yaml
snippets/tpl.040.network.sh
snippets/tpl.041.network-el9.sh

index 959c4b5cf28a29e6a266c0a62403b9db0a30c730..d04060baec053932320b4f9f411fbeafaf44b7c4 100644 (file)
@@ -47,7 +47,7 @@ cobbler-distros:
       - 'tpl.001.basics.sh'
       # - 'tpl.005.update_resolvconf.sh'
       - 'tpl.010.authkeys.sh'
-      - 'tpl.040.network.sh'
+      - 'tpl.041.network-el9.sh'
       - 'tpl.060.tweak_systemd.sh'
       - 'tpl.070.tweak_grub.sh'
       - 'tpl.075.tmp-tmpfs.sh'
index e101b6c83ee4df90fc972e33119d87cf8edda1ba..972be99b0b5c4a55b47fe9638a64a3f7fede3306 100644 (file)
@@ -41,11 +41,21 @@ create_networkconfig() {
     /bin/hostname "${base_hostname}"
     echo "${base_hostname}" > '/etc/hostname'
 
+    # Setting the hostname with hostnamectl ...
+    echo "Setting the hostname ..."
+    hostnamectl set-hostname --static "${base_hostname}"
+    hostnamectl set-hostname --transient "${base_hostname}"
+    hostnamectl set-deployment "${system_status}"
+    hostnamectl set-location "L105 / VMWare"
+
+    hostnamectl status
+
+    echo
     echo "Updating '/etc/hosts' ..."
     echo >>'/etc/hosts'
     echo "${ip_address_eth0}   ${hostname}     ${base_hostname}" >>'/etc/hosts'
     echo "Generated /etc/hosts:"
-    cat '/etc/hosts' | true
+    cat '/etc/hosts' || true
     echo
 
     for ifcfg_file in ${nw_script_dir}/ifcfg-* ; do
index e101b6c83ee4df90fc972e33119d87cf8edda1ba..3930f538e0f105f1bdbee967cfbc9f70126dacb9 100644 (file)
@@ -11,54 +11,33 @@ create_networkconfig() {
     log "Generating network configuration ..."
 
     local temp_dir=$( mktemp -p /tmp -d 'tmp.XXXXXXXXXX.cobbler' )
-    local tmp_nw_cfg="${temp_dir}/network"
     local tmp_nw_script_dir="${temp_dir}/network-scripts"
     local nw_script_dir="/etc/sysconfig/network-scripts"
-    local nw_old_dir="${nw_script_dir}/.old"
     local nm_cfg_dir='/etc/NetworkManager/system-connections'
     local nm_old_dir="${nm_cfg_dir}/.old"
     local ifcfg_file=
     local if_uuid=$( uuidgen -r )
 
     mkdir -pv "${tmp_nw_script_dir}"
-    mkdir -pv "${nw_old_dir}"
     mkdir -pv "${nm_old_dir}"
 
-    echo "Generating /etc/sysconfig/network ..."
+    # Setting the hostname with hostnamectl ...
+    echo "Setting the hostname ..."
+    hostnamectl hostname --static "${base_hostname}"
+    hostnamectl hostname --transient "${base_hostname}"
+    hostnamectl deployment "${system_status}"
+    hostnamectl location "L105 / VMWare"
 
-    grep -v 'GATEWAY|HOSTNAME' /etc/sysconfig/network > "${tmp_nw_cfg}"
-    echo "GATEWAY=${gateway}"   >> "${tmp_nw_cfg}"
-    echo "HOSTNAME=${hostname}" >> "${tmp_nw_cfg}"
-    mv -v /etc/sysconfig/network "/etc/sysconfig/network.orig.$( date -r /etc/sysconfig/network +'%Y-%m-%d_%H:%M:%S' )"
-    mv -v "${tmp_nw_cfg}" /etc/sysconfig/network
+    hostnamectl status --json pretty
 
-    echo "Generated /etc/sysconfig/network:"
-    cat /etc/sysconfig/network || true
     echo
-
-    # Also set the hostname now, some applications require it
-    echo "Generating '/etc/hostname' ..."
-    /bin/hostname "${base_hostname}"
-    echo "${base_hostname}" > '/etc/hostname'
-
     echo "Updating '/etc/hosts' ..."
     echo >>'/etc/hosts'
     echo "${ip_address_eth0}   ${hostname}     ${base_hostname}" >>'/etc/hosts'
     echo "Generated /etc/hosts:"
-    cat '/etc/hosts' | true
+    cat '/etc/hosts' || true
     echo
 
-    for ifcfg_file in ${nw_script_dir}/ifcfg-* ; do
-        if [[ ! -f "${ifcfg_file}" ]] ; then
-            continue
-        fi
-        local bname=$(basename "${ifcfg_file}" )
-        if [[ "${bname}" == "ifcfg-lo" ]] ; then
-            continue
-        fi
-        mv -v "${ifcfg_file}" "${nw_old_dir}"
-    done
-
     for ifcfg_file in ${nm_cfg_dir}/*.nmconnection ; do
         if [[ ! -f "${ifcfg_file}" ]] ; then
             continue