Qemu build image on kvm hypervisor

Hi Team,

I have vhd disk that contains OEL9 operating system, using this disk I need to make some configuration changes using packer in order to create kvm image.
I’m following the QEMU packer build documentation, Now I want to create this image using vhd file and need to perform configuration using ansible provisioner.

Could you please let me know what are all the parameters I need to add it. Here is my snippet:

{
“builders”: [
{
“vm_name”: “Demo-VM”,

  "disk_image": true,
  "iso_url": "my_existing_image.vhd",
  "iso_checksum_type": "none",

  "output_directory": "Output-Image",

  "ssh_username": "",
  "ssh_password": "",
  "ssh_pty": true,
  "ssh_wait_timeout": "2m",

  "shutdown_command": "echo 'centos' | sudo -S /sbin/halt -h -p",

  "type": "qemu",
  "headless": true,
  "memory": "8192",
  "cpus": 4
}

],
“post-processors”: null,
“provisioners”: [
{
“type”: “ansible”,
“playbook_file”: “./My_playbook.yml”
}
]
}

  1. You first need to drop the json and use hcl instead. It’s easier to read,
    or at least I find it easier to read.

  2. Use the three tildes to make your code readable on the forum.

```plain
Like this
```

Like this
  1. Extra parameters you need:
  • A packer block that contains the required qemu plugin.
  • boot_command
  • accelerator
  • disk_interface
  • http_directory

I’m getting the below error while running the packer code for kvm

==> qemu: Connecting to VM via VNC (0.0.0.0:5931)
==> qemu: Typing the boot commands over VNC…
==> qemu: Waiting for the guest address to become available in the virbr0 network bridge…
==> qemu: Using SSH communicator to connect: 192.x.x.x
==> qemu: Waiting for SSH to become available…
==> qemu: Timeout waiting for SSH.
==> qemu: Deleting output directory…
Build ‘qemu’ errored after 8 minutes 47 seconds: Timeout waiting for SSH.

==> Wait completed after 8 minutes 47 seconds

==> Some builds didn’t complete successfully and had errors:
→ qemu: Timeout waiting for SSH.

==> Builds finished but no artifacts were created.

You need your script to add your ssh username and password,
corresponding to the one you wrote down in your packer build file
and turn on the ssh service.

I have added that already in my json file.

I’m running this packer code on KVM hyper visor machine.

Also i’m using qcow2 file by mentioning in iso_url path

Please let me know if anything i need to enable.

I have added that already in my json file.

That’s what I call the packer build file.
It’s actually called the packer template in the documentation,
but I hadn’t looked that up in my previous.

How do you build up your box?
In the My_playbook.yml?
Can you show that code?
I’m not familiar with ansible.

Your provisioner files (My_playbook.yml) should have ssh username and password added and correspond to the ones in your packer template.