CentOS 7 Kickstart-Datei, Eintrag zu /etc/hosts hinzufügen

CentOS 7 Kickstart-Datei, Eintrag zu /etc/hosts hinzufügen

Ich habe eine CentOS 7-Kickstart-Datei, die größtenteils ganz gut funktioniert. Der %packagesAbschnitt schlägt fehl, weil ich einen Eintrag zu /etc/hosts hinzufügen muss, um mirrorlist.centos.org auf unser internes Firmenrepo zu verweisen. Ich kann den Eintrag %postproblemlos in den Abschnitt einfügen, aber er scheint nach den Paketen ausgeführt zu werden. Ich habe versucht, ihn dem %preAbschnitt hinzuzufügen, aber er erscheint nie in /etc/hosts. Laut der Dokumentation wird der Abschnitt „pre“ ausgeführt, bevor die Installation beginnt, daher gehe ich davon aus, dass das Dateisystem noch nicht einmal existiert. Ich kann die Pakete in den %postAbschnitt verschieben und einfach ausführen yum install <my package>, aber ich dachte, es wäre etwas übersichtlicher, wenn ich den Abschnitt „packages“ verwenden würde. Hier ist meine vollständige Kickstart-Datei:

install
cdrom
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --noipv6 --onboot=on --device=eth0
rootpw --plaintext XXXX
firewall --disabled
selinux --permissive
timezone UTC
unsupported_hardware
bootloader --timeout=1 --location=mbr --append="net.ifnames=0 biosdevname=0"
text
skipx
zerombr
clearpart --all --initlabel
autopart --nohome --nolvm
auth --enableshadow --passalgo=sha512 --kickstart
firstboot --disabled
reboot --eject
user --name=vagrant --plaintext --password XXXX

%packages --nobase --ignoremissing --excludedocs --instLangs=en_US.utf8
# vagrant needs this to copy initial files via scp
openssh-clients
sudo
selinux-policy-devel
wget
nfs-utils
net-tools
tar
bzip2
deltarpm
rsync
qemu-guest-agent
-fprintd-pam
-intltool

# unnecessary firmware
-*firmware
-microcode_ctl
%end

%pre --log=/mnt/ks-pre.log
#!/bin/sh
echo X.X.X.X   mirrorlist.centos.org >> /etc/hosts
touch /mnt/hello
touch /root/hello
%end

%post --log=/root/ks-post.log
echo X.X.X.X mirrorlist.centos.org >> /etc/hosts
# sudo
echo 'Defaults:vagrant !requiretty' > /etc/sudoers.d/vagrant
echo '%vagrant ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers.d/vagrant
chmod 440 /etc/sudoers.d/vagrant

# Enable hyper-v daemons only if using hyper-v virtualization
if [ $(virt-what) == "hyperv" ]; then
    yum -y install hyperv-daemons cifs-utils
    systemctl enable hypervvssd
    systemctl enable hypervkvpd
fi

# Since we disable consistent network naming, we need to make sure the eth0
# configuration file is in place so it will come up.
# Delete other network configuration first because RHEL/C7 networking will not
# restart successfully if there are configuration files for devices that do not
# exist.
rm -f /etc/sysconfig/network-scripts/ifcfg-e*
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 << _EOF_
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
DEVICE=eth0
ONBOOT=yes
_EOF_

#add our SSH key as a login method
mkdir /root/.ssh
chmod 700 /root/.ssh
cat >> /root/.ssh/authorized_keys << _EOF_
ssh-rsa xxxxxx
_EOF_
chmod 600 /root/.ssh/authorized_keys

#cloud init
yum install -y cloud-init
cat > /etc/cloud/cloud.cfg.d/90_dpkg.cfg << _EOF_
datasource_list: [ NoCloud, None ]
_EOF_
systemctl enable cloud-init

cat > /etc/cloud/cloud.cfg << _EOF_
users:
 - default

disable_root: 0
ssh_pwauth:   1

mount_default_fields: [~, ~, 'auto', 'defaults,nofail,x-systemd.requires=cloud-init.service', '0', '2']
resize_rootfs_tmp: /dev
ssh_deletekeys:   0
ssh_genkeytypes:  ~
syslog_fix_perms: ~
disable_vmware_customization: true

cloud_init_modules:
 - disk_setup
 - migrator
 - bootcmd
 - write-files
 - growpart
 - resizefs
 - set_hostname
 - update_hostname
 - update_etc_hosts
 - rsyslog
 - users-groups
 - ssh

cloud_config_modules:
 - mounts
 - locale
 - set-passwords
 - rh_subscription
 - yum-add-repo
 - package-update-upgrade-install
 - timezone
 - puppet
 - chef
 - salt-minion
 - mcollective
 - disable-ec2-metadata
 - runcmd

cloud_final_modules:
 - rightscale_userdata
 - scripts-per-once
 - scripts-per-boot
 - scripts-per-instance
 - scripts-user
 - ssh-authkey-fingerprints
 - keys-to-console
 - phone-home
 - final-message
 - power-state-change

system_info:
  default_user:
    name: centos
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

# vim:syntax=yaml
_EOF_

echo Complete

%end

Antwort1

Ich möchte nur meine eigene Frage beantworten, basierend auf den Informationen von @HBruijn. Es scheint, dass der Paketabschnitt nur dazu gedacht ist, Pakete vom Installationsmedium zu installieren. Das ist sinnvoll, da Sie während der Installationsphase des Betriebssystems im Allgemeinen keine externen Repos verwenden würden. Im Allgemeinen würden Sie das Betriebssystem installieren und dann zusätzliche Pakete installieren. Daher ist es sinnvoll, hierfür den Postabschnitt zu verwenden. Dort ist es einfach, einen Eintrag hinzuzufügen /etc/hostsund dann zusätzliche Pakete zu installieren.

verwandte Informationen