Packer VSphere-ISO Centos 7 网络连接出现问题

Packer VSphere-ISO Centos 7 网络连接出现问题

虽然我刚接触 Packer 和 Kickstart 脚本,但我正尝试在 VSphere 集群中自动设置 CentOS 7(最终是 8)机箱。我的 Packer 代码正在调用 Kickstart 脚本来完成设置,但在网络工作时遇到了问题。由于 ESX 集群中的每个节点都是 6.5.X,我认为不需要 Guest IP hack。

当我运行“packer build --debug”并使用 PACLOG=1 以获得更详细的信息时,我发现我的代码无法完成“等待 IP...”步骤:

==> vsphere-iso: Adding generated Floppy...
==> vsphere-iso: Set boot order...
==> vsphere-iso: Power on VM...
==> vsphere-iso: Waiting 10s for boot...
==> vsphere-iso: Typing boot command...
2020/06/09 18:40:15 packer-builder-vsphere-iso plugin: Special code '<esc>' found, replacing with: CodeEscape
2020/06/09 18:40:15 packer-builder-vsphere-iso plugin: Waiting 1 second
2020/06/09 18:40:20 packer-builder-vsphere-iso plugin: Special code '<enter>' found, replacing with: CodeReturnEnter
2020/06/09 18:40:20 packer-builder-vsphere-iso plugin: Waiting 1 second
2020/06/09 18:40:21 packer-builder-vsphere-iso plugin: [INFO] Waiting for IP, up to total timeout: 30m0s, settle timeout: 5s
==> vsphere-iso: Waiting for IP...
==> vsphere-iso: Post "https://<server name>.com/sdk": EOF
==> vsphere-iso: Step "StepWaitForIp" failed

在虚拟机中运行安装程序(无论是否使用 GUI 安装程序),我都会看到虚拟机中未配置网络(适配器已启动但没有 IP)。由于适配器名称不一致,我尝试让 Packer 使用任何连接的适配器,并使用 DHCP 来简化大规模部署。我尝试过“network --onboot yes --device=link --activate”和“network --onboot yes --activate”以及其他组合。每次在 /etc/sysconfig/network-scripts/ 下都会创建一个文件,但网络仍未建立。

我用硬编码变量替换了 Packer JSON 中的所有变量,但得到的结果相同。

作为验证,我还可以看到临时虚拟机在 VSphere 中被列为属于网络的虚拟机,并且它具有有效的 MAC。

我也尝试确保安装了 open-vm-tools 包,但没有帮助。

有人遇到过这个问题吗?

打包文件中的 Builders 部分:

   "builders": [
      {
      "type": "vsphere-iso",

      "vcenter_server": "{{user `vsphere-server`}}",
      "username": "{{user `vsphere-user`}}",
      "password": "{{user `vsphere-password`}}",
      "insecure_connection": "true",

      "datacenter": "{{user `vsphere-datacenter`}}",
      "cluster": "{{user `vsphere-cluster`}}",
      "network": "{{user `vsphere-network`}}",
      "host": "{{user `vsphere-host`}}",
      "datastore": "{{user `vsphere-datastore`}}",

      "vm_name": "{{user `vm-name`}}",
      "notes": "Build via Packer",
      "guest_os_type": "centos7_64Guest",

      "boot_wait": "10s",
      "boot_order": "disk,cdrom,floppy",

      "communicator": "ssh",
      "ssh_username": "root",
      "ssh_password": "server",

      "CPUs": "{{user `vm-cpu-num`}}",
      "RAM": "{{user `vm-mem-size`}}",
      "RAM_reserve_all": false,
      "disk_controller_type": "pvscsi",
      "disk_size": "{{user `vm-disk-size`}}",
      "disk_thin_provisioned": true,
      "network_card": "vmxnet3",

      "convert_to_template": true,

      "iso_urls": ["{{user `iso-url`}}"],
      "iso_checksum": "{{user `iso-checksum`}}",
      "iso_checksum_type": "{{user `iso-checksum-type`}}",
      "floppy_files": ["ks.cfg"],
      "boot_command": [
        "<esc><wait>",
        "linux inst.text ks=hd:fd0:/ks.cfg<enter><wait>"

KS.cfg:

```# Install a fresh new system (optional)
install

# Specify installation method to use for installation
# To use a different one comment out the 'url' one below, update
# the selected choice with proper options & un-comment it
cdrom

# Set language to use during installation and the default language to use on the installed system (required)
lang en_US.UTF-8

# Set system keyboard type / layout (required)
keyboard --vckeymap=us --xlayouts='us'

firstboot --disable
# Configure network information for target system and activate network devices in the installer environment (optional)
# --onboot  enable device at a boot time
# --device  device to be activated and / or configured with the network command
# --bootproto   method to obtain networking configuration for device (default dhcp)
# --noipv6  disable IPv6 on this device
network --onboot yes --bootproto dhcp --noipv6
#network --bootproto=dhcp --onboot=yes --device=link --noipv6 --activate

# Set the system's root password (required)
# Plaintext password is: server
rootpw --iscrypted $6$rhel6usgcb$aS6oPGXcPKp3OtFArSrhRwu6sN8q2.yEGY7AIwDOQd23YCtiz9c5mXbid1BzX9bmXTEZi.hCzTEXFosVBI5ng0

# Configure firewall settings for the system (optional)
# --enabled reject incoming connections that are not in response to outbound requests
# --ssh     allow sshd service through the firewall
# firewall --enabled --ssh
firewall --disabled

# Set up the authentication options for the system (required)
# --enableshadow    enable shadowed passwords by default
# --passalgo        hash / crypt algorithm for new passwords
# See the manual page for authconfig for a complete list of possible options.
authconfig --enableshadow --passalgo=sha512

# State of SELinux on the installed system (optional)
# Defaults to enforcing
selinux --permissive

# Set the system time zone (required)
timezone --utc America/Chicago

# Specify how the bootloader should be installed (required)
# Plaintext password is: password
bootloader --location=mbr --append="crashkernel=auto rhgb quiet" --password=$6$rhel6usgcb$kOzIfC4zLbuo3ECp1er99NRYikN419wxYMmons8Vm/37Qtg0T8aB9dKxHwqapz8wWAFu
autopart --type=lvm

# Initialize all disks

clearpart --linux --initlabel

services --enabled=NetworkManager,sshd
# Packages selection
%packages --ignoremissing
Require @Base
@Base
@minimal

# End of %packages section

%post
#sudo yum upgrade -y
yum -y install open-vm-tools
yum -y install sudo
systemctl enable vmtoolsd
systemctl start vmtoolsd
systemctl enable sshd
systemctl start sshd
%end

# Reboot after the installation is complete (optional)
# --eject   attempt to eject CD or DVD media before rebooting
reboot --eject

相关内容