Packer HCL, vsphere-iso, waiting for ssh

Hi Folks,

Did anybody try packer with HCL and vsphere-iso builder? I’m testing a new config (below) with default centos iso

source "vsphere-iso" "default" {
    vcenter_server      = var.vcenter_server
    username            = var.username
    password            = var.password
    insecure_connection = true
    cluster             = var.cluster
    datacenter          = var.datacenter
    host                = var.host  # w/o host it doesn't work. I think there is a bug opened in GH to fix that. 
    datastore           = var.datastore
    iso_urls          = [var.iso_urls]
    iso_checksum      = var.iso_checksum
    iso_checksum_type = "sha256"
    vm_name               = "packer_tml_jbl_${ var.image_os }_std_{{ isotime \"2006-01-02\" }}"
    guest_os_type         = var.guest_os_type
    disk_thin_provisioned = true
    disk_size             = 45000
    network_card          = "vmxnet3"
    network               = "VM Network"
    CPUs                  = 2
    cpu_cores             = 2
    CPU_hot_plug          = true
    RAM                   = 4096
    RAM_hot_plug          = true
    floppy_files = [
      "./scripts/ks-centos.cfg"
    ]
    boot_command = ["<tab> initrd=initrd.img net.ifnames=0 biosdevname=0 inst.text ksdevice=eth0 inst.ks=hd:fd0:/ks-centos.cfg <enter><wait>"]
    ssh_username = "root"
    ssh_password = "${var.ssh_password}"
    ssh_timeout  = "10m"!
    shutdown_command = "echo 'packer' | sudo -S /sbin/halt -h -p"
}

build {
  sources = [
    "source.vsphere-iso.default"
  ]
  provisioner "shell" {
    execute_command = "echo 'packer' | {{ .Vars }} sudo -S -E bash '{{ .Path }}'"
    scripts = [
        "./scripts/set-linuxsettings.sh"
    ]
  }
}

It looks like packer can’t authenticate via ssh (username and pass). When I try to connect to the VM via ssh with same creds, it works fine.

packer -version
1.5.5

packer log:

2020/04/13 14:23:19 packer.exe plugin: [INFO] Attempting SSH connection to 192.168.1.33:22...
2020/04/13 14:23:19 packer.exe plugin: [DEBUG] reconnecting to TCP connection for SSH
2020/04/13 14:23:19 packer.exe plugin: [DEBUG] handshaking with SSH
2020/04/13 14:23:21 packer.exe plugin: [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
2020/04/13 14:23:21 packer.exe plugin: [DEBUG] Detected authentication error. Increasing handshake attempts.

ks.cfg (short version)

repo --name="CentOS" --baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ --cost=100
install
cdrom
lang en_US
keyboard us
# Root password 
rootpw --iscrypted <our encrypted pass her> 
# Use text mode install
text
# System authorization information
auth  --useshadow  --passalgo=sha512
# Firewall configuration
firewall --enabled --ssh
selinux --permissive
logging --level=info
skipx
network --device enp0s3 --bootproto dhcp
timezone --utc America/New_York
# Reboot after installation
reboot --eject
%packages
@core --nodefaults
%end
%addon com_redhat_kdump --disable
%end
%post --log=/var/log/ks.post02.log
#!/bin/bash
# Install sdc-vmtools guest tools
# required to detect IP when building on ESXi
echo "Installing VM Tools..."
sudo yum -y install open-vm-tools
sudo systemctl enable vmtoolsd
sudo systemctl start vmtoolsd
%end

As in most of such cases, the issues was with ks.cfg. I don’t know why it allowed to ssh with the same password via native ssh but packer couldn’t.

Anyway, as soon as I re-created the encrypted password, it started to work.

1 Like