From: Frank Brehm Date: Tue, 31 Oct 2023 12:39:46 +0000 (+0100) Subject: Changing network snippets to use hostnamectl to change the hostname. X-Git-Tag: 3.2.1~40^2~12 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=64e6baff6e5b249a19aa098391632f194b2b97ac;p=pixelpark%2Fcreate-vmware-tpl.git Changing network snippets to use hostnamectl to change the hostname. --- diff --git a/etc/cobbler-distros.d/rhel-9.yaml b/etc/cobbler-distros.d/rhel-9.yaml index 959c4b5..d04060b 100644 --- a/etc/cobbler-distros.d/rhel-9.yaml +++ b/etc/cobbler-distros.d/rhel-9.yaml @@ -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' diff --git a/snippets/tpl.040.network.sh b/snippets/tpl.040.network.sh index e101b6c..972be99 100644 --- a/snippets/tpl.040.network.sh +++ b/snippets/tpl.040.network.sh @@ -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 diff --git a/snippets/tpl.041.network-el9.sh b/snippets/tpl.041.network-el9.sh index e101b6c..3930f53 100644 --- a/snippets/tpl.041.network-el9.sh +++ b/snippets/tpl.041.network-el9.sh @@ -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