0

We have recently run into an issue where ipconfig is no longer able to pick up networking during the post install portion of our anaconda kickstart file.

This is preventing our boxes from installing puppet and they have to be manually tweaked when booting up a box. This is a huge pain and gets us away from being completely automated in our infrastructure. We are a small company and cannot afford to do these types of tasks manually.

I have tried to use both the new ip package and nmcli to get the network information.

ip actually picks up information during the post install process but no IP address is present at this time. nmcli doesn't pick up anything at all. Below is a screenshot of what is being pulled by the ip address during the post install (as you can see no ip at this point).

ip address command output

Below is a step by step play by play, of what I am trying to achieve.

  1. Setup network to look for a DHCP lease (there is only ever one possible)
  2. Use some form of networking package to list the ip address, gateway, ect.
  3. Parse the data in bash and then move it into my eth0 interface file.
  4. Install puppet before the kickstart finishes, so that is available to start by itself after reboot.

My kickstart file is below with the various methods I have tried (sorry it's a bit messy but I have litterally been going back and forth trying to make different things work).

install
url --url http://repo1.example.com/centos/7/os/x86_64
lang en_US.UTF-8
keyboard us
timezone --utc America/Vancouver
network --noipv6 --onboot=yes --bootproto=dhcp --activate --device=eth0
authconfig --enableshadow --passalgo=sha512
rootpw --iscrypted ************************************
firewall --enabled --port 22:tcp
selinux --permissive
bootloader --location=mbr --driveorder=vda --append="crashkernel=auth rhgb"

# Disk Partitioning
  zerombr
  clearpart --all --drives=vda
  part / --fstype=ext4 --grow --asprimary --size=200
  part swap --size=4096
# END of Disk Partitioning

# Make sure we reboot into the new system when we are finished
reboot

repo --name=base --baseurl=http://repo1.example.com/centos/7/os/x86_64/

# Package Selection
%packages --nobase 
@core
wget
NetworkManager
-rsyslog
%end

%pre
echo "------------------------- IP COMMANDS ---------------------"
ip address
ip route
echo "------------------------- IP COMMANDS ---------------------"
%end

%post --log=/root/install-post.log (

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# PLACE YOUR POST DIRECTIVES HERE

echo "**************************************************"
echo "Converting DHCP scope to static IP address on eth0"
echo "**************************************************"

### NMCLI DOES NOT WORK IN KICKSTART
# IPADDR=`nmcli con show eth0 | grep IP4.ADDRESS | awk '{sub(/IP4.ADDRESS[1]:/,""); print $2}'`
# GATEWAY=`nmcli con show eth0 | grep IP4.GATEWAY | awk '{sub(/IP4.GATEWAY[1]:/,""); print $2}'`
# DNS1=`nmcli con show eth0 | grep "IP4.DNS\[1\]" | awk '{sub(/IP4.DNS[1]:/,""); print $2}'` 
# DNS2=`nmcli con show eth0 | grep "IP4.DNS\[2\]" | awk '{sub(/IP4.DNS[2]:/,""); print $2}'`

## LETS TRY IP as IPCONFIG is EOL
IPADDR=`ip address | grep global | awk '{print $2}' | cut -d / -f1`
GATEWAY=`ip route | grep default | awk '{print $2}'`

echo "------------------------- IP COMMANDS ---------------------"
ip address
ip route
echo "------------------------- IP COMMANDS ---------------------"


echo "##### TEST NMCLI"
echo "IP ADDRES: " $IPADDR
echo "GATEWAY: " $GATEWAY
echo "DNS1: " $DNS1
echo "DNS2: " $DNS2


#nmcli con mod eth0 ipv4.dns $DNS1 
#nmcli con mod eth0 +ipv4.dns $DNS2
#nmcli con mod eth0 ipv4.addresses $IPADDR
#nmcli con mod eth0 ipv4.dns-search example.com
#nmcli con mod eth0 ipv4.gateway $GATEWAY
#nmcli con mod eth0 ipv4.method manual


echo "************************************"
echo "Network test and to clear ARP caches"
echo "************************************"

ping -c 4 repo1.example.com

echo "************"
echo "Setup Puppet"
echo "************"
/usr/bin/wget "https://yum.puppetlabs.com/el/7/products/x86_64/puppetlabs-release-7-12.noarch.rpm"
/usr/bin/rpm -Uvh "puppetlabs-release-7-12.noarch.rpm"
/usr/bin/sed -i "s/yum.puppetlabs.com/repo1.example.com\/puppetlabs/g" /etc/yum.repos.d/puppetlabs.repo
/usr/bin/yum -y --nogpgcheck install puppet
/usr/bin/sed -i 's/\[main\]/\[main\]\nenvironment=infrastructure/g' /etc/puppet/puppet.conf
/usr/bin/echo "server = puppet1.example.com" >> /etc/puppet/puppet.conf
/usr/bin/echo "configtimeout = 30m" >> /etc/puppet/puppet.conf
puppet agent --test # this shouldn't fail
puppet agent --test # this shouldn't fail
puppet agent --test # this shouldn't fail
service puppet start
/usr/sbin/chkconfig puppet on


echo "START NETWORK *********************************"

DEVICE=`route -n | grep '^0.0.0.0' | awk '{print $8}'`
IPADDR=`ifconfig $DEVICE  | grep 'inet ' | awk '{print $2}'`
NETMASK=`ifconfig $DEVICE | grep 'inet ' | awk '{print $4}'`
# NETWORK=`ipcalc $IPADDR -n $NETMASK| cut -d = -f2`
GATEWAY=`route -n|grep '^0.0.0.0'| awk '{print $2}'`
HWADDR=`ifconfig $DEVICE|grep 'ether'| awk '{print $2}'`
# UUID=`uuidgen $DEVICE`

cat <<EOF >/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=$HOSTNAME
GATEWAY=$GATEWAY
EOF

cat <<EOF >/etc/sysconfig/network-scripts/ifcfg-$DEVICE
# NAME=$DEVICE
DEVICE=$DEVICE
BOOTPROTO=static
IPADDR=$IPADDR
NETMASK=$NETMASK
ONBOOT=yes
GATEWAY=$GATEWAY
HWADDR=$HWADDR
DNS1=10.1.1.23
DNS2=10.1.1.24
# UUID=$UUID
EOF
echo "END NETWORK *********************************"

)
%end
Husk Rekoms
  • 217
  • 1
  • 4
  • 15
  • Why are you doing _anything at all_ to the networking configuration in `%post`? – Michael Hampton Mar 15 '19 at 00:49
  • 1
    Because I want to make the ip address static on boot.... – Husk Rekoms Mar 15 '19 at 14:17
  • But won't your DHCP server try to assign it again later? Better to use DHCP reservations. – Michael Hampton Mar 15 '19 at 15:38
  • No, we convert it to a static address in the actual interface file. At that point the address becomes static. Anyways, I am open to changing our process. It's something I inherited coming here, and it just broke this week. Thanks for the advice, I'll look into DHCP reservations will work for what I need to achieve. – Husk Rekoms Mar 15 '19 at 17:32

0 Answers0