From f270ef5b15914dba3138c79a8a79422b22c32618 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 18 Jun 2020 18:01:19 +0200 Subject: [PATCH] Adding and using snippets/tpl.040.network.sh --- kickstart/template-centos8.ks | 19 ++++++--- snippets/tpl.001.basics.sh | 1 + snippets/tpl.040.network.sh | 76 +++++++++++++++++++++++++++++++++ snippets/tpl.300.create-motd.sh | 2 + 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 snippets/tpl.040.network.sh diff --git a/kickstart/template-centos8.ks b/kickstart/template-centos8.ks index 5bf9bf2..6e2fd56 100644 --- a/kickstart/template-centos8.ks +++ b/kickstart/template-centos8.ks @@ -147,18 +147,20 @@ rm -rf /var/var export hostname="$hostname" export system_name="$system_name" export gateway="$gateway" +export mgmt_interface="eth0" export ip_address_eth0="$ip_address_eth0" export mac_address_eth0="$mac_address_eth0" export system_status="${SYSTEM_STATUS}" export ws_rel_filesdir="${WS_REL_FILESDIR}" echo -echo "hostname: '$hostname'" -echo "system_name: '$system_name'" -echo "gateway: '$gateway'" -echo "ip_address_eth0: '$ip_address_eth0'" -echo "mac_address_eth0: '$mac_address_eth0'" -echo "System status: '${system_status}'" +echo "hostname: '$hostname'" +echo "system_name: '$system_name'" +echo "gateway: '$gateway'" +echo "Management interface: '${mgmt_interface}'" +echo "ip_address_eth0: '$ip_address_eth0'" +echo "mac_address_eth0: '$mac_address_eth0'" +echo "System status: '${system_status}'" #set $basic_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.001.basics.sh" echo @@ -170,6 +172,11 @@ echo echo "Using snippet $authkeys_snippet" $SNIPPET($authkeys_snippet) +#set $network_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.040.network.sh" +echo +echo "Using snippet $network_snippet" +$SNIPPET($network_snippet) + #set $tweak_systemd_snippet = "per_status/" + $SYSTEM_STATUS + "/tpl.060.tweak_systemd.sh" echo echo "Using snippet $tweak_systemd_snippet" diff --git a/snippets/tpl.001.basics.sh b/snippets/tpl.001.basics.sh index a344967..d1309d1 100644 --- a/snippets/tpl.001.basics.sh +++ b/snippets/tpl.001.basics.sh @@ -49,6 +49,7 @@ echo "Some information:" echo " \$hostname: $hostname" echo " \$system_name: $system_name" echo " \$gateway: $gateway" +echo " \$management_interface: ${mgmt_interface}" echo " \$mac_address_eth0: $mac_address_eth0" echo " \$ip_address_eth0: $ip_address_eth0" echo " \$IP_ADDRESS_ETH0: $IP_ADDRESS_ETH0" diff --git a/snippets/tpl.040.network.sh b/snippets/tpl.040.network.sh new file mode 100644 index 0000000..34fe130 --- /dev/null +++ b/snippets/tpl.040.network.sh @@ -0,0 +1,76 @@ +## !/bin/bash +#raw + +#----------------------------------------------------------- +create_networkconfig() { + + echo + echo "${HASH_LINE}" + echo + 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 old_dir="${nw_script_dir}/.old" + local ifcfg_file= + local if_uuid=$( uuidgen -r ) + + mkdir -pv "${tmp_nw_script_dir}" + mkdir -pv "${old_dir}" + + echo "Generating /etc/sysconfig/network ..." + + 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 + + echo "Generated /etc/sysconfig/network:" + cat /etc/sysconfig/network || true + echo + + # Also set the hostname now, some applications require it + /bin/hostname "${hostname}" + + local dev_file="${tmp_nw_script_dir}/ifcfg-${mgmt_interface}" + echo "Generating '${dev_file}' ..." + + cat <<-EOF >"${dev_file}" + NAME="${mgmt_interface}" + DEVICE="${mgmt_interface}" + ONBOOT=yes + NETBOOT=yes + UUID="${if_uuid}" + IPV6INIT=yes + BOOTPROTO=dhcp + TYPE=Ethernet + EOF + + for ifcfg_file in ${nw_script_dir}/ifcfg-* ; do + local bname=$(basename "${ifcfg_file}" ) + if [[ "${bname}" == "ifcfg-lo" ]] ; then + continue + fi + mv -v "${ifcfg_file}" "${old_dir}" + done + mv -v "${dev_file}" "${nw_script_dir}" + rm -vrf "${temp_dir}" + + echo "Generated ${nw_script_dir}/ifcfg-${mgmt_interface}:" + cat "${nw_script_dir}/ifcfg-${mgmt_interface}" || true + echo + + echo + echo "${HASH_LINE}" + echo "Inhalt von /etc/sysconfig/network-scripts ..." + ls -lA /etc/sysconfig/network-scripts + +} + +create_networkconfig + +#end raw +## vim: ts=4 et list diff --git a/snippets/tpl.300.create-motd.sh b/snippets/tpl.300.create-motd.sh index 77d60b9..8a557c0 100644 --- a/snippets/tpl.300.create-motd.sh +++ b/snippets/tpl.300.create-motd.sh @@ -17,6 +17,8 @@ create_motd() { if wget -O "${mk_script}" --dns-timeout=2 --connect-timeout=3 --read-timeout=3 "${url}" ; then chmod 0755 "${mk_script}" "${mk_script}" > /etc/motd + mkdir -pv /root/bin + cp -pv "${mk_script}" /root/bin/create-motd.sh else echo "[$(date)]: Could not get 'mk_create_motd.ksh' from '${url}'." | tee -a "${ERROR_POINTER}" fi -- 2.39.5