packer-plugin-qemu
                                
                                
                                
                                    packer-plugin-qemu copied to clipboard
                            
                            
                            
                        Qemu builder doesn't work on rhel8-based systems
This issue was originally opened by @anderpups as hashicorp/packer#10892. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.
Overview of the Issue
When trying the qemu builder on RHEL8-based systems. It errors out with:
 Qemu driver: exec: \"qemu-system-x86_64\": executable file not found in $PATH"
It seems they have changed the name and location of the above binary to /usr/libexec/qemu-kvm . The package qemu-system-x86_64 has been replaced with qemu-kvm package
I was able to get it to work by setting the below symbolic link.
ln -s /usr/libexec/qemu-kvm /usr/local/bin/qemu-system-x86_64
Reproduction Steps
Install Packer on any RHEL8-based system (RHEL, CentOS, Oracle, etc.) and the build will fail on the above error
Packer version
1.72
Simplified Packer Buildfile
{
    "builders": [
        {
            "name": "packer_step1_oel8_qemu",
            "vm_name": "packer_step1_oel8.qcow2",
            "cpus": "1",
            "memory": "2048",
            "disk_size": "54G",
            "format": "qcow2",
            "type": "qemu",
            "accelerator": "kvm",
            "boot_command": [
                "<esc>",
                "<wait5>",
                "linux inst.cmdline inst.ip=dhcp inst.ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/oel8_centos8_bootable.ks.cfg",
                "<enter>"
            ],
            "headless": "True",
            "http_directory": "files/packer_http_directory",
            "iso_url": "https://artifacts.dti.state.de.us/artifactory/iso/oel8/oracle_linux_8-3_bootable.iso",
            "iso_checksum": "771e383adfd5406d1a360ff24822011a88cbb45b6019e2f1095758c46a406aaa",
            "output_directory": "output/step1/oel8/qemu",
            "ssh_username": "packer",
            "ssh_password": "packer",
            "ssh_timeout": "20m"
        }
    ],
    "provisioners": [
        {
            "ansible_env_vars": "ANSIBLE_ROLES_PATH=~/repos",
            "extra_arguments": "--become",
            "playbook_file": "repos/dti_linux_packer_image_prep/packer_step1.yml",
            "type": "ansible",
            "user": "packer"
        }
    ]
}
Operating system and Environment details
Centos8
Log Fragments and crash.log files
[vagrant@packer-builder ~]$ packer build packer_step1_oel8.json 
2021/04/08 14:41:11 [INFO] Packer version: 1.7.2 [go1.16.3 linux amd64]
2021/04/08 14:41:11 [TRACE] discovering plugins in /home/vagrant/.local/bin
2021/04/08 14:41:11 [TRACE] discovering plugins in /home/vagrant/.packer.d/plugins
2021/04/08 14:41:11 [TRACE] discovering plugins in .
2021/04/08 14:41:11 [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/04/08 14:41:11 [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/vagrant/.packerconfig
2021/04/08 14:41:11 [WARN] Config file doesn't exist: /home/vagrant/.packerconfig
2021/04/08 14:41:11 [INFO] Setting cache directory: /home/vagrant/packer_cache
2021/04/08 14:41:11 [TRACE] Starting internal plugin packer-builder-qemu
2021/04/08 14:41:11 Starting plugin: /home/vagrant/.local/bin/packer []string{"/home/vagrant/.local/bin/packer", "plugin", "packer-builder-qemu"}
2021/04/08 14:41:11 Waiting for RPC address for: /home/vagrant/.local/bin/packer
2021/04/08 14:41:11 packer-builder-qemu plugin: [INFO] Packer version: 1.7.2 [go1.16.3 linux amd64]
2021/04/08 14:41:11 packer-builder-qemu plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/04/08 14:41:11 packer-builder-qemu plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/vagrant/.packerconfig
2021/04/08 14:41:11 packer-builder-qemu plugin: [WARN] Config file doesn't exist: /home/vagrant/.packerconfig
2021/04/08 14:41:11 packer-builder-qemu plugin: [INFO] Setting cache directory: /home/vagrant/packer_cache
2021/04/08 14:41:11 packer-builder-qemu plugin: args: []string{"packer-builder-qemu"}
2021/04/08 14:41:11 packer-builder-qemu plugin: Plugin address: unix /tmp/packer-plugin138730911
2021/04/08 14:41:11 packer-builder-qemu plugin: Waiting for connection...
2021/04/08 14:41:11 Received unix RPC address for /home/vagrant/.local/bin/packer: addr is /tmp/packer-plugin138730911
2021/04/08 14:41:11 packer-builder-qemu plugin: Serving a plugin connection...
2021/04/08 14:41:11 [TRACE] Starting internal plugin packer-provisioner-ansible
2021/04/08 14:41:11 Starting plugin: /home/vagrant/.local/bin/packer []string{"/home/vagrant/.local/bin/packer", "plugin", "packer-provisioner-ansible"}
2021/04/08 14:41:11 Waiting for RPC address for: /home/vagrant/.local/bin/packer
2021/04/08 14:41:11 packer-provisioner-ansible plugin: [INFO] Packer version: 1.7.2 [go1.16.3 linux amd64]
2021/04/08 14:41:11 packer-provisioner-ansible plugin: [INFO] PACKER_CONFIG env var not set; checking the default config file path
2021/04/08 14:41:11 packer-provisioner-ansible plugin: [INFO] PACKER_CONFIG env var set; attempting to open config file: /home/vagrant/.packerconfig
2021/04/08 14:41:11 packer-provisioner-ansible plugin: [WARN] Config file doesn't exist: /home/vagrant/.packerconfig
2021/04/08 14:41:11 packer-provisioner-ansible plugin: [INFO] Setting cache directory: /home/vagrant/packer_cache
2021/04/08 14:41:11 packer-provisioner-ansible plugin: args: []string{"packer-provisioner-ansible"}
2021/04/08 14:41:11 packer-provisioner-ansible plugin: Plugin address: unix /tmp/packer-plugin936073015
2021/04/08 14:41:11 packer-provisioner-ansible plugin: Waiting for connection...
2021/04/08 14:41:11 Received unix RPC address for /home/vagrant/.local/bin/packer: addr is /tmp/packer-plugin936073015
2021/04/08 14:41:11 packer-provisioner-ansible plugin: Serving a plugin connection...
2021/04/08 14:41:11 Preparing build: packer_step1_oel8_qemu
2021/04/08 14:41:11 packer-builder-qemu plugin: use specified accelerator: kvm
2021/04/08 14:41:11 Build debug mode: false
2021/04/08 14:41:11 Force build: false
2021/04/08 14:41:11 On error: 
2021/04/08 14:41:11 packer-provisioner-ansible plugin: ansible-playbook version: 2.10.7
2021/04/08 14:41:11 Waiting on builds to complete...
2021/04/08 14:41:11 Starting build run: packer_step1_oel8_qemu
2021/04/08 14:41:11 Running builder: qemu
2021/04/08 14:41:11 [INFO] (telemetry) Starting builder qemu
packer_step1_oel8_qemu: output will be in this color.
2021/04/08 14:41:11 [INFO] (telemetry) ending qemu
==> Wait completed after 556 microseconds
2021/04/08 14:41:11 machine readable: error-count []string{"1"}
==> Some builds didn't complete successfully and had errors:
2021/04/08 14:41:11 machine readable: packer_step1_oel8_qemu,error []string{"Failed creating Qemu driver: exec: \"qemu-system-x86_64\": executable file not found in $PATH"}
==> Builds finished but no artifacts were created.
2021/04/08 14:41:11 [INFO] (telemetry) Finalizing.
Build 'packer_step1_oel8_qemu' errored after 524 microseconds: Failed creating Qemu driver: exec: "qemu-system-x86_64": executable file not found in $PATH
                                    
                                    
                                    
                                
It works, you have to set "qemu_binary" in the template. Would be nice if it found it automatically.
Thanks for the hints folks!