Hello,
I’m trying to setup a virtual machine using packer but even after the installation completes I cannot get any artifacts as the SSH provide cannot connect to QEMU.
I even resorted disabling the NAT SSH port, I hardcoded it but still get this message:
PACKER_LOG=1 packer build .
2022/04/14 17:00:49 [INFO] Packer version: 1.8.0 [go1.17.8 linux amd64]
2022/04/14 17:00:49 [TRACE] discovering plugins in /usr/bin
2022/04/14 17:00:49 [TRACE] discovering plugins in /home/jose/.config/packer/plugins
2022/04/14 17:00:49 [TRACE] discovering plugins in .
2022/04/14 17:00:49 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2022/04/14 17:00:49 [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/jose/.packerconfig
2022/04/14 17:00:49 [WARN] Config file doesn't exist: /home/jose/.packerconfig
2022/04/14 17:00:49 [INFO] Setting cache directory: /home/jose/.cache/packer
2022/04/14 17:00:49 [TRACE] Starting internal plugin packer-builder-qemu
2022/04/14 17:00:49 Starting plugin: /usr/bin/packer []string{"/usr/bin/packer", "plugin", "packer-builder-qemu"}
2022/04/14 17:00:49 Waiting for RPC address for: /usr/bin/packer
2022/04/14 17:00:49 packer-builder-qemu plugin: [INFO] Packer version: 1.8.0 [go1.17.8 linux amd64]
2022/04/14 17:00:49 packer-builder-qemu plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2022/04/14 17:00:49 packer-builder-qemu plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/jose/.packerconfig
2022/04/14 17:00:49 packer-builder-qemu plugin: [WARN] Config file doesn't exist: /home//jose/.packerconfig
2022/04/14 17:00:49 packer-builder-qemu plugin: [INFO] Setting cache directory: /home//jose/.cache/packer
2022/04/14 17:00:49 packer-builder-qemu plugin: args: []string{"packer-builder-qemu"}
2022/04/14 17:00:49 packer-builder-qemu plugin: Plugin address: unix /tmp/packer-plugin2007554095
2022/04/14 17:00:49 packer-builder-qemu plugin: Waiting for connection...
2022/04/14 17:00:49 Received unix RPC address for /usr/bin/packer: addr is /tmp/packer-plugin2007554095
2022/04/14 17:00:49 packer-builder-qemu plugin: Serving a plugin connection...
2022/04/14 17:00:49 packer-builder-qemu plugin: use specified accelerator: kvm
2022/04/14 17:00:49 Build debug mode: false
2022/04/14 17:00:49 Force build: false
2022/04/14 17:00:49 On error:
2022/04/14 17:00:49 Waiting on builds to complete...
2022/04/14 17:00:49 Starting build run: qemu.fedora
2022/04/14 17:00:49 Running builder:
2022/04/14 17:00:49 [INFO] (telemetry) Starting builder qemu.fedora
qemu.fedora: output will be in this color.
2022/04/14 17:00:49 packer-builder-qemu plugin: Qemu path: /usr/bin/qemu-system-x86_64, Qemu Image path: /usr/bin/qemu-img
==> qemu.fedora: Retrieving ISO
==> qemu.fedora: Trying http://ny2lxavt082p.nologies.com:8081/repository/avt-static/fedora/Fedora-Server-dvd-x86_64-29-1.2.iso
2022/04/14 17:00:49 packer-builder-qemu plugin: Acquiring lock for: http://ny2lxavt082p.nologies.com:8081/repository/avt-static/fedora/Fedora-Server-dvd-x86_64-29-1.2.iso?checksum=md5%3A4962e7136516120d40e4289ede5a974d (/home//jose/.cache/packer/b97374ee9f2769529cbc362c18833941211fe333.iso.lock)
==> qemu.fedora: Trying http://ny2lxavt082p.nologies.com:8081/repository/avt-static/fedora/Fedora-Server-dvd-x86_64-29-1.2.iso?checksum=md5%3A4962e7136516120d40e4289ede5a974d
2022/04/14 17:00:54 packer-builder-qemu plugin: Leaving retrieve loop for ISO
2022/04/14 17:00:54 packer-builder-qemu plugin: No floppy files specified. Floppy disk will not be made.
2022/04/14 17:00:54 packer-builder-qemu plugin: No CD files specified. CD disk will not be made.
2022/04/14 17:00:54 packer-builder-qemu plugin: [INFO] Creating disk with Path: output_fedora/fedora and Size: 50000M
2022/04/14 17:00:54 packer-builder-qemu plugin: Executing qemu-img: []string{"create", "-f", "qcow2", "output_fedora/fedora", "50000M"}
==> qemu.fedora: http://ny2lxavt082p.nologies.com:8081/repository/avt-static/fedora/Fedora-Server-dvd-x86_64-29-1.2.iso?checksum=md5%3A4962e7136516120d40e4289ede5a974d => /home//jose/.cache/packer/b97374ee9f2769529cbc362c18833941211fe333.iso
2022/04/14 17:00:54 packer-builder-qemu plugin: stdout: Formatting 'output_fedora/fedora', fmt=qcow2 size=52428800000 cluster_size=65536 lazy_refcounts=off refcount_bits=16
2022/04/14 17:00:54 packer-builder-qemu plugin: stderr:
2022/04/14 17:00:54 packer-builder-qemu plugin: Found available port: 8273 on IP: 0.0.0.0
==> qemu.fedora: Starting HTTP server on port 8273
2022/04/14 17:00:54 packer-builder-qemu plugin: Skipping NAT port forwarding. Using communicator (SSH, WinRM, etc) port 2280
==> qemu.fedora: Looking for available port between 5900 and 5900 on 0.0.0.0
2022/04/14 17:00:54 packer-builder-qemu plugin: Looking for available port between 5900 and 5900 on 0.0.0.0
2022/04/14 17:00:54 packer-builder-qemu plugin: Found available port: 5900 on IP: 0.0.0.0
2022/04/14 17:00:54 packer-builder-qemu plugin: Found available VNC port: 5900 on IP: 0.0.0.0
2022/04/14 17:00:54 packer-builder-qemu plugin: Qemu --version output: QEMU emulator version 3.0.0 (qemu-3.0.0-3.fc29)
2022/04/14 17:00:54 packer-builder-qemu plugin: Copyright (c) 2003-2017 Fabrice Bellard and the QEMU Project developers
2022/04/14 17:00:54 packer-builder-qemu plugin: Qemu version: 3.0.0
==> qemu.fedora: Starting VM, booting from CD-ROM
qemu.fedora: view the screen of the VM, connect via VNC without a password to
qemu.fedora: vnc://0.0.0.0:5900
qemu.fedora: The VM will be run headless, without a GUI. If you want to
qemu.fedora: view the screen of the VM, connect via VNC without a password to
qemu.fedora: vnc://0.0.0.0:5900
2022/04/14 17:00:54 packer-builder-qemu plugin: Qemu Builder has no floppy files, not attaching a floppy.
2022/04/14 17:00:54 packer-builder-qemu plugin: Executing /usr/bin/qemu-system-x86_64: []string{"-netdev", "user,id=user.0,hostfwd=tcp::2280-:2280", "-m", "16000M", "-device", "virtio-net-pci,netdev=user.0", "-boot", "once=d", "-drive", "file=output_fedora/fedora,if=virtio,cache=writeback,discard=ignore,format=qcow2", "-drive", "file=/home//jose/.cache/packer/b97374ee9f2769529cbc362c18833941211fe333.iso,media=cdrom", "-name", "fedora", "-machine", "type=pc-q35-2.10,accel=kvm", "-vnc", "0.0.0.0:0", "-smp", "cpus=8,sockets=8"}
2022/04/14 17:00:54 packer-builder-qemu plugin: Started Qemu. Pid: 26446
==> qemu.fedora: Waiting 10s for boot...
==> qemu.fedora: Connecting to VM via VNC (0.0.0.0:5900)
2022/04/14 17:01:06 packer-builder-qemu plugin: Connected to VNC desktop: QEMU (fedora)
==> qemu.fedora: Typing the boot command over VNC...
2022/04/14 17:01:06 packer-builder-qemu plugin: Special code '<tab>' found, replacing with: 0xFF09
2022/04/14 17:01:06 packer-builder-qemu plugin: Sending char ' ', code 0x20, shift false
2022/04/14 17:01:06 packer-builder-qemu plugin: Sending char 't', code 0x74, shift false
2022/04/14 17:01:06 packer-builder-qemu plugin: Sending char 'e', code 0x65, shift false
2022/04/14 17:01:07 packer-builder-qemu plugin: Sending char 'x', code 0x78, shift false
2022/04/14 17:01:07 packer-builder-qemu plugin: Sending char 't', code 0x74, shift false
2022/04/14 17:01:07 packer-builder-qemu plugin: Sending char ' ', code 0x20, shift false
2022/04/14 17:01:07 packer-builder-qemu plugin: Sending char 'k', code 0x6B, shift false
2022/04/14 17:01:07 packer-builder-qemu plugin: Sending char 's', code 0x73, shift false
2022/04/14 17:01:08 packer-builder-qemu plugin: Sending char '=', code 0x3D, shift false
2022/04/14 17:01:08 packer-builder-qemu plugin: Sending char 'h', code 0x68, shift false
2022/04/14 17:01:08 packer-builder-qemu plugin: Sending char 't', code 0x74, shift false
2022/04/14 17:01:08 packer-builder-qemu plugin: Sending char 't', code 0x74, shift false
2022/04/14 17:01:08 packer-builder-qemu plugin: Sending char 'p', code 0x70, shift false
2022/04/14 17:01:09 packer-builder-qemu plugin: Sending char ':', code 0x3A, shift true
2022/04/14 17:01:09 packer-builder-qemu plugin: Sending char '/', code 0x2F, shift false
2022/04/14 17:01:09 packer-builder-qemu plugin: Sending char '/', code 0x2F, shift false
2022/04/14 17:01:09 packer-builder-qemu plugin: Sending char '1', code 0x31, shift false
2022/04/14 17:01:10 packer-builder-qemu plugin: Sending char '0', code 0x30, shift false
2022/04/14 17:01:10 packer-builder-qemu plugin: Sending char '.', code 0x2E, shift false
2022/04/14 17:01:10 packer-builder-qemu plugin: Sending char '0', code 0x30, shift false
2022/04/14 17:01:10 packer-builder-qemu plugin: Sending char '.', code 0x2E, shift false
2022/04/14 17:01:10 packer-builder-qemu plugin: Sending char '2', code 0x32, shift false
2022/04/14 17:01:11 packer-builder-qemu plugin: Sending char '.', code 0x2E, shift false
2022/04/14 17:01:11 packer-builder-qemu plugin: Sending char '2', code 0x32, shift false
2022/04/14 17:01:11 packer-builder-qemu plugin: Sending char ':', code 0x3A, shift true
2022/04/14 17:01:11 packer-builder-qemu plugin: Sending char '8', code 0x38, shift false
2022/04/14 17:01:12 packer-builder-qemu plugin: Sending char '2', code 0x32, shift false
2022/04/14 17:01:12 packer-builder-qemu plugin: Sending char '7', code 0x37, shift false
2022/04/14 17:01:12 packer-builder-qemu plugin: Sending char '3', code 0x33, shift false
2022/04/14 17:01:12 packer-builder-qemu plugin: Sending char '/', code 0x2F, shift false
2022/04/14 17:01:12 packer-builder-qemu plugin: Sending char 'f', code 0x66, shift false
2022/04/14 17:01:13 packer-builder-qemu plugin: Sending char 'e', code 0x65, shift false
2022/04/14 17:01:13 packer-builder-qemu plugin: Sending char 'd', code 0x64, shift false
2022/04/14 17:01:13 packer-builder-qemu plugin: Sending char 'o', code 0x6F, shift false
2022/04/14 17:01:13 packer-builder-qemu plugin: Sending char 'r', code 0x72, shift false
2022/04/14 17:01:13 packer-builder-qemu plugin: Sending char 'a', code 0x61, shift false
2022/04/14 17:01:14 packer-builder-qemu plugin: Sending char '2', code 0x32, shift false
2022/04/14 17:01:14 packer-builder-qemu plugin: Sending char '9', code 0x39, shift false
2022/04/14 17:01:14 packer-builder-qemu plugin: Sending char '-', code 0x2D, shift false
2022/04/14 17:01:14 packer-builder-qemu plugin: Sending char 'k', code 0x6B, shift false
2022/04/14 17:01:14 packer-builder-qemu plugin: Sending char 's', code 0x73, shift false
2022/04/14 17:01:15 packer-builder-qemu plugin: Sending char '.', code 0x2E, shift false
2022/04/14 17:01:15 packer-builder-qemu plugin: Sending char 'c', code 0x63, shift false
2022/04/14 17:01:15 packer-builder-qemu plugin: Sending char 'f', code 0x66, shift false
2022/04/14 17:01:15 packer-builder-qemu plugin: Sending char 'g', code 0x67, shift false
2022/04/14 17:01:16 packer-builder-qemu plugin: Special code '<enter>' found, replacing with: 0xFF0D
2022/04/14 17:01:16 packer-builder-qemu plugin: [INFO] Waiting 1s
qemu.fedora: Not using a NetBridge -- skipping StepWaitGuestAddress
2022/04/14 17:01:17 packer-builder-qemu plugin: Using host value: 127.0.0.1
==> qemu.fedora: Using SSH communicator to connect: 127.0.0.1
2022/04/14 17:01:17 packer-builder-qemu plugin: [INFO] Waiting for SSH, up to timeout: 15m0s
==> qemu.fedora: Waiting for SSH to become available...
2022/04/14 17:01:17 packer-builder-qemu plugin: Using host value: 127.0.0.1
2022/04/14 17:01:17 packer-builder-qemu plugin: [INFO] Attempting SSH connection to 127.0.0.1:2280...
2022/04/14 17:01:17 packer-builder-qemu plugin: [DEBUG] reconnecting to TCP connection for SSH
2022/04/14 17:01:17 packer-builder-qemu plugin: [DEBUG] handshaking with SSH
2022/04/14 17:02:17 packer-builder-qemu plugin: [DEBUG] SSH handshake err: Timeout during SSH handshake
2022/04/14 17:02:24 packer-builder-qemu plugin: Using host value: 127.0.0.1
2022/04/14 17:02:24 packer-builder-qemu plugin: [INFO] Attempting SSH connection to 127.0.0.1:2280...
2022/04/14 17:02:24 packer-builder-qemu plugin: [DEBUG] reconnecting to TCP connection for SSH
2022/04/14 17:02:24 packer-builder-qemu plugin: [DEBUG] handshaking with SSH
2022/04/14 17:03:24 packer-builder-qemu plugin: [DEBUG] SSH handshake err: Timeout during SSH handshake
2022/04/14 17:03:31 packer-builder-qemu plugin: Using host value: 127.0.0.1
2022/04/14 17:03:31 packer-builder-qemu plugin: [INFO] Attempting SSH connection to 127.0.0.1:2280...
2022/04/14 17:03:31 packer-builder-qemu plugin: [DEBUG] reconnecting to TCP connection for SSH
2022/04/14 17:03:31 packer-builder-qemu plugin: [DEBUG] handshaking with SSH
2022/04/14 17:04:31 packer-builder-qemu plugin: [DEBUG] SSH handshake err: Timeout during SSH handshake
2022/04/14 17:16:10 packer-builder-qemu plugin: [DEBUG] SSH handshake err: ssh: handshake failed: EOF
==> qemu.fedora: Timeout waiting for SSH.
2022/04/14 17:16:17 packer-builder-qemu plugin: failed to unlock port lockfile: close tcp 0.0.0.0:5900: use of closed network connection
2022/04/14 17:16:17 packer-builder-qemu plugin: [DEBUG] SSH wait cancelled. Exiting loop.
==> qemu.fedora: Deleting output directory...
2022/04/14 17:16:17 [INFO] (telemetry) ending qemu.fedora
==> Wait completed after 15 minutes 28 seconds
2022/04/14 17:16:17 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2022/04/14 17:16:17 machine readable: qemu.fedora,error []string{"Timeout waiting for SSH."}
==> Builds finished but no artifacts were created.
Build 'qemu.fedora' errored after 15 minutes 28 seconds: Timeout waiting for SSH.
==> Wait completed after 15 minutes 28 seconds
==> Some builds didn't complete successfully and had errors:
2022/04/14 17:16:17 [INFO] (telemetry) Finalizing.
--> qemu.fedora: Timeout waiting for SSH.
==> Builds finished but no artifacts were created.
2022/04/14 17:16:17 waiting for all plugin processes to complete...
2022/04/14 17:16:17 /usr/bin/packer: plugin process exited
My HCL2 packer file looks like this:
/*
* https://www.packer.io/plugins/builders/qemu
* https://wiki.qemu.org/Documentation/Networking
* https://www.qemu.org/docs/master/system/images.html
* https://github.com/jakobadam/packer-qemu-templates
* https://www.linux-kvm.org/page/Networking#User_Networking
* PACKER_LOG=1 packer build .
* On a separate terminal: vinagre vnc://127.0.0.1:5987 > /dev/null 2>&1 &
* NOTE: Possible performance issue, may need to add a TAP device. BUT that requires GTS to give us an IP address we can use https://wiki.qemu.org/Documentation/Networking#Tap
*/
source "qemu" "fedora" {
iso_url = "http://webserver.company.com:8081/repository/avt-static/fedora/Fedora-Server-dvd-x86_64-29-1.2.iso"
iso_checksum = "md5:4962e7136516120d40e4289ede5a974d"
output_directory = "output_fedora"
shutdown_command = "echo 'XXXX' | sudo -S shutdown -P now"
disk_size = "50000M"
format = "qcow2"
accelerator = "kvm"
http_directory = "kickstart"
# communicator = "none"
# Disabled NAT as port forwarding doesn't work for non-root user
skip_nat_mapping = "true"
ssh_port = "2280"
ssh_username = "systemuser"
ssh_password = "systemuser"
ssh_timeout = "15m"
vm_name = "fedora"
net_device = "virtio-net-pci"
# scsi is not allowed under RedHat due a bug.
disk_interface = "virtio"
boot_wait = "10s"
headless = "true"
cpus = "8"
memory = "16000"
vnc_bind_address = "0.0.0.0"
vnc_port_min = "5900"
vnc_port_max = "5900"
machine_type = "pc-q35-2.10"
boot_command = ["<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/fedora-ks.cfg<enter><wait>"]
}
build {
sources = ["source.qemu.fedora"]
}
And my kickstart file:
# Please check: https://pykickstart.readthedocs.io/en/latest/
# Lint the file: ksvalidator fedora29-ks.cfg
# Jose Vicente Nunez (mycompany.com)
bootloader --append="nofb ipv6.disable=1 selinux=0 noselinux geoloc=0 consoleblank=0 audit=0" --location=mbr
text
repo --name="os" --baseurl=http://repo.mycompany.com/repo/Fedora/XX/os --cost=1
repo --name="os-updates" --baseurl=http://repo.mycompany.com/repo/Fedora/XX/updates --cost=1
url --url="http://repo.mycompany.com/repo/Fedora/XX/os"
keyboard --vckeymap=us --xlayouts=''
lang en_US.UTF-8
network --hostname=virtual29
rootpw --plaintext XXXX
authselect --useshadow --passalgo=sha256 --kickstart
selinux --disabled
firstboot --disabled
skipx
services --enable="chronyd" --enabled="sshd"
timezone America/New_York --isUtc --ntpservers=ntp.mycompany.com
clearpart --all --initlabel
part /boot --fstype="ext4" --size=512 --fsoptions="noatime"
part /var --fstype="xfs" --size=10240 --fsoptions="noatime"
part swap --fstype="swap" --size=8192
part / --fstype="xfs" --size=30000 --grow --fsoptions="noatime"
part biosboot --fstype="biosboot" --size=1
user --name=systemuser --groups=YYY --password=XXXXX
reboot
%pre --erroronfail
echo "Nothing to see here"
%end
%pre-install --erroronfail --interpreter /usr/bin/python3
"""
/mnt/sysimage is available, make some changes to YUM repositories
"""
from pathlib import Path
REPO_PATH = Path("/mnt/sysimage/etc/yum.repos.d")
REPO_PATH.mkdir(parents=True, exist_ok=True)
REPOS = {
"os": "http://repo.mycompany.com/repo/Fedora/XX/os",
"os-updates": "http://repo.mycompany.com/repo/Fedora/XX/updates"
}
for repo, url in REPOS.items():
repo_file = REPO_PATH.joinpath(f"{repo}.repo")
print(f"Creating {repo_file}")
with open(repo_file, "w") as repod:
repod.write(f'''[{repo}]
name={repo}
enabled=1
baseurl={url}
gpgcheck=0
''')
%end
%post --interpreter /bin/bash --erroronfail
exec < /dev/tty3 > /dev/tty3
/bin/chvt 3
(
set -x
for disabled in fedora fedora-modular updates updates-modular updates-testing fedora-cisco-openh264; do
/bin/dnf config-manager --set-disabled $disabled
done
/bin/sed -i "s/#PermitRootLogin yes/PermitRootLogin yes/g" /etc/ssh/sshd_config
/usr/bin/systemctl enable sshd
set +x
) 2>&1| /bin/tee /root/ks-post-services.log
/bin/chvt 1
%end
%post --interpreter /bin/bash --erroronfail
exec < /dev/tty3 > /dev/tty3
/bin/chvt 3
(
set -x
/bin/cat<<SUDOERS>/etc/sudoers.d/systemuser
systemuser ALL=(ALL) NOPASSWD: ALL
Defaults:systemuser env_keep += SSH_AUTH_SOCK
SUDOERS
chmod 0440 /etc/sudoers.d/systemuser
/bin/sed -i 's/^.*requiretty/#Defaults requiretty/' /etc/sudoers
/bin/cat<<PUBLIC_KEY>/home/systemuser/.ssh/authorized_keys
ssh-rsa 6u6wBvvEvYXlwy3yZSfdDhACSRvL/4OfpMlN7TCDf39aL8sUh0QxCmYiPmrlZjASSomlFjtRFEs1Mc3/gZptvfcHSeA4OhK9vfZpeZ3gyj1UT1CQuVAzUFY28EHbPfB+iE4elI+r3M/fZAN92Ilz3Iw7YAKeihbaovka8RyklE7/FfQ5MEMs1ypa9fbz+D systemuser@mycompany.com
PUBLIC_KEY
/bin/chmod 0600 /home/systemuser/.ssh/systemuser
/bin/chown -R systemuser:mygroup /home/systemuser/.ssh
set +x
) 2>&1| /bin/tee /root/ks-post-sudoers.log
/bin/chvt 1
%end
%post --interpreter /bin/bash --erroronfail
exec < /dev/tty3 > /dev/tty3
/bin/chvt 3
(
set -x
/usr/bin/dnf -y update
/usr/bin/dnf -y -q clean all
/bin/rm -rf /var/cache/dnf/*
/usr/bin/dnf -y -q remove NetworkManager* PackageKit* cups* jack-audio* gstreamer* iw firewalld* ModemManager-glib
set +x
) 2>&1| /bin/tee /root/ks-post-packages.log
/bin/chvt 1
%end
%post --interpreter /bin/bash --erroronfail
exec < /dev/tty3 > /dev/tty3
/bin/chvt 3
(
set -x
sync
sync
sleep 1
sync
sleep 1
set +x
) 2>&1| /bin/tee /root/ks-post-useradd.log
/bin/chvt 1
%end
%packages
@core
@standard
dnf-plugins-core
augeas
dhclient
dnf-plugins-extras-versionlock
kernel-devel
network-scripts
ntpdate
perl
-puppet-3.8.4
rsyslog
ruby-augeas
rubygem-xmlrpc
vim-minimal
wget
yum
-PackageKit-glib
-abrt-cli
-cups
-emacs
-geolite2-city
-hunspell
-nano
-pinfo
procps-ng
which
net-tools
iproute
iputils
traceroute
findutils
hostname
htop
bind-utils
kernel-tools
kmod
%end
%addon com_redhat_kdump --disable --reserve-mb='128'
%end
Any ideas what I could be doing wrong?
I’m not running packer as root.
Thanks!