【发布时间】:2017-09-22 16:36:12
【问题描述】:
我正在使用 Jenkins 自动部署虚拟设备。第一步是在 KVM 中构建一个标准的 CentOS 7 最小 vm。我编写了一个简短的 bash 脚本来执行此任务,该任务在 KVM 机器上本地运行时有效:
#!/bin/bash
#Variables
diskpath="/var/lib/libvirt/images/"
buildname=$(date +"%m-%d-%y-%H-%M")
vmextension=".dsk"
#Change to images directory
cd /var/lib/libvirt/images/
#Deploy VM with with kickstart file
sudo virt-install \
--name=$buildname \
--nographics \
--hvm \
--virt-type=kvm \
--file=$diskpath$buildname$vmextension \
--file-size=20 \
--nonsparse \
--vcpu=2 \
--ram=2048 \
--network bridge=br0 \
--os-type=linux \
--os-variant=generic \
--location=http://0.0.0.0/iso/ \
--initrd-inject /var/lib/libvirt/images/autobuild-ks.cfg \
--extra-args="ks=http://0.0.0.0/ks/autobuild-ks.cfg console=ttyS0"
(出于安全考虑,我更改了 IP 地址)
ISO 和 kickstart 文件存储在另一台服务器上,它们都可以通过 http 访问以使该脚本正常工作。需要明确的是,该脚本确实有效。
我遇到的问题是,当我将此脚本作为构建步骤放入 Jenkins 时,该脚本有效;但是,在安装完 OS 并且 kvm guest 开始关闭过程后,它会在最后挂起。
这里是 kickstart 文件:
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use Network installation media
url --url=http://0.0.0.0/iso
# Use graphical install
#graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=gb --xlayouts='gb'
# System language
lang en_GB.UTF-8
# Network information
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network --hostname=hostname.domain.com
# Root password
rootpw --iscrypted
taken_encryption_output_out_for_the_purposes_of_security
#Shutdown after installation
shutdown
# System services
services --enabled="chronyd"
# System timezone
timezone Europe/London --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-
drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
pwpolicy user --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
pwpolicy luks --minlen=6 --minquality=50 --notstrict --nochanges --
notempty
%end
我怀疑这与 Kickstart 文件中的关闭选项有关,但不确定。当我 ssh 到 kvm 服务器时,我可以看到我新创建的 vm,因此脚本可以正常工作,但 Jenkins 挂起。
[root@sut-kvm01 ~]# virsh list --all
Id Name State
----------------------------------------------------
- 09-22-17-16-21 shut off
到目前为止,我已经尝试关闭、重新启动,显然停止是 kickstart 文件中的默认设置,但它们也对我不起作用。
任何想法如何让构建成功完成?如果它挂起,我将无法继续执行构建步骤 2。
请帮忙:-)
【问题讨论】: