terraform-libvirt-vm icon indicating copy to clipboard operation
terraform-libvirt-vm copied to clipboard

Error: couldn't retrieve IP address of domain id

Open tuxpeople opened this issue 3 years ago • 1 comments

Hi

First, I want to thank for this module! Second, this is most probably not a bug, but any help would be appreciated.

This is my terraform file:

terraform {
  required_version = ">= 0.13"
  required_providers {
    libvirt = {
      source  = "dmacvicar/libvirt"
      version = "<=0.6.13"
    }
  }
}

provider "libvirt" {
  uri = "qemu+ssh://user@host/system?keyfile=/Users/name/.ssh/id_rsa"
}


module "terra_pool" {
  count  = 3
  source = "srb3/pool/libvirt"
  name   = "terra_pool"
  path   = "/data/virt/vms/pools/terra_pool"
}


module "vm" {
  source  = "MonolithProjects/vm/libvirt"
  version = "1.9.0"

  vm_hostname_prefix = "server"
  vm_count           = 3
  memory             = "2048"
  vcpu               = 1
  pool               = "terra_pool"
  system_volume      = 20
  dhcp               = true
  bridge             = "bridge99"
  local_admin        = "local-admin"
  ssh_admin          = "ansible"
  ssh_private_key    = "~/.ssh/id_rsa"
  local_admin_passwd = "$6$rounds=4096$xxxxxxxxHASHEDxxxPASSWORD"
  ssh_keys = [
    "ssh-rsa AAAAB3NzaxxxxxxxTnggNEDpnY/Ir08XkjuCjqKKwAJ68xkHrWxiQ== name",
  ]
  time_zone  = "CEST"
  os_img_url = "http://mirror.chpc.utah.edu/pub/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2"
}

output "ip_addresses" {
  value = module.vm
}

Terraform quits with that error:

Error: Error: couldn't retrieve IP address of domain id: 7e45f93e-4042-495a-94ed-4629f296b56a. Please check following: 
│ 1) is the domain running proplerly? 
│ 2) has the network interface an IP address? 
│ 3) Networking issues on your libvirt setup? 
│  4) is DHCP enabled on this Domain's network? 
│ 5) if you use bridge network, the domain should have the pkg qemu-agent installed 
│ IMPORTANT: This error is not a terraform libvirt-provider error, but an error caused by your KVM/libvirt infrastructure configuration/setup 
│  timeout while waiting for state to become 'all-addresses-obtained' (last state: 'waiting-addresses', timeout: 5m0s)
│ 
│   with module.vm.libvirt_domain.virt-machine[0],
│   on .terraform/modules/vm/main.tf line 12, in resource "libvirt_domain" "virt-machine":
│   12: resource "libvirt_domain" "virt-machine" {
│ 
╵

But it has worked, it creates the VMs, VMs are running and accessible via SSH. It's just the check witch fails. But I'm not sure if I need to search the cause in this module or the provider.

When I go to the libvirt host, I see the created vms:

# virsh list
 Id    Name                           Status
----------------------------------------------------
 13    server02                       laufend
 14    server01                       laufend
 15    server03                       laufend

As it is bridged to the hosts network, my understanding is that it needs the qemu-agent installed. I verified it is:

[root@server02 ~]# systemctl status qemu-guest-agent
● qemu-guest-agent.service - QEMU Guest Agent
   Loaded: loaded (/usr/lib/systemd/system/qemu-guest-agent.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2022-03-30 11:33:34 UTC; 14min ago
 Main PID: 1182 (qemu-ga)
    Tasks: 1 (limit: 12296)
   Memory: 1020.0K
   CGroup: /system.slice/qemu-guest-agent.service
           └─1182 /usr/bin/qemu-ga --method=virtio-serial --path=/dev/virtio-ports/org.qemu.guest_agent.0 --blacklist=guest-file-open,guest-file-close,guest-file-read,guest-file-write,guest->

Mar 30 11:33:34 server02 systemd[1]: qemu-guest-agent.service: Succeeded.
Mar 30 11:33:34 server02 systemd[1]: Stopped QEMU Guest Agent.
Mar 30 11:33:34 server02 systemd[1]: Started QEMU Guest Agent.

I also verified qemu can get the IP address from it's agent:

# virsh domifaddr --source agent --domain server02
 Name       MAC-Adresse          Protocol     Address
-------------------------------------------------------------------------------
 lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
 -          -                    ipv6         ::1/128
 eth0       52:54:00:06:43:75    ipv4         192.168.8.135/24
 -          -                    ipv6         fe80::5054:ff:fe06:4375/64

Do you have an Idea what I'm doing wrong here?

tuxpeople avatar Mar 30 '22 11:03 tuxpeople

Did you test it with ubuntu or debian?

chrodriguez avatar Mar 30 '22 13:03 chrodriguez