terraform-provider-libvirt: output ip fail with bridge and I need it for my ansible inventory

System Information

Linux distribution

Ubuntu 18.04.4 LTS

Terraform version

+ provider.libvirt (unversioned)
+ provider.template v2.1.2

Provider and libvirt versions

terraform-provider-libvirt 0.6.2+git.1585292411.8cbe9ad0
Compiled against library: libvirt 4.0.0
Using library: libvirt 4.0.0
Running hypervisor: QEMU 2.11.1
Running against daemon: 4.0.0

Description of Issue/Question

Setup

provider "libvirt" {
  uri = "qemu:///system"
}
terraform {
  required_version = ">= 0.12"
}
resource "libvirt_pool" "debian" {
  name = "debian"
  type = "dir"
  path = "/srv/terraform-provider-libvirt-pool-debian"
}
resource "libvirt_volume" "debian-qcow2" {
  name   = "debian-qcow2"
  pool   = libvirt_pool.debian.name
  source = "https://cdimage.debian.org/cdimage/openstack/current/debian-10.3.2-20200406-openstack-amd64.qcow2"
  format = "qcow2"
}
resource "libvirt_volume" "disk_debian_resized" {
  name           = "disk"
  base_volume_id = libvirt_volume.debian-qcow2.id
  pool           = libvirt_pool.debian.name
  size           = 2 * 1024 * 1024 * 1024
}
data "template_file" "user_data" {
  template = file("${path.module}/cloud_init.cfg")
}
data "template_file" "network_config" {
  template = file("${path.module}/network_config.cfg")
}
resource "libvirt_cloudinit_disk" "commoninit" {
  name           = "commoninit.iso"
  user_data      = data.template_file.user_data.rendered
  network_config = data.template_file.network_config.rendered
  pool           = libvirt_pool.debian.name
}
resource "libvirt_domain" "domain-debian" {
  name   = "debian-terraform"
  memory = "2048"
  vcpu   = 2
  qemu_agent = true
  cloudinit = libvirt_cloudinit_disk.commoninit.id
  disk {
    volume_id = libvirt_volume.disk_debian_resized.id
  }
  network_interface {
    bridge = "br0"
    wait_for_lease = true
  }

provisioner "local-exec" {
    command = "virsh qemu-agent-command debian-terraform '{\"execute\":\"guest-network-get-interfaces\"}'|jq     '.return[1].\"ip-addresses\"[0].\"ip-address\"'| sed 's/\"//g'"
}

  console {
    type        = "pty"
    target_port = "0"
    target_type = "serial"
  }
  console {
    type        = "pty"
    target_type = "virtio"
    target_port = "1"
  }
  graphics {
    type        = "spice"
    listen_type = "address"
    autoport    = true
  }
}

output "ips" {
  # show IP, run 'terraform refresh' if not populated
  value = libvirt_domain.domain-debian.*.network_interface.0.addresses
}

Additional information:

terraform apply
libvirt_pool.debian: Creating...
libvirt_pool.debian: Creation complete after 5s [id=289d6454-ff34-4552-9c29-8b12042b0b35]
libvirt_cloudinit_disk.commoninit: Creating...
libvirt_volume.debian-qcow2: Creating...
libvirt_volume.debian-qcow2: Still creating... [10s elapsed]
libvirt_cloudinit_disk.commoninit: Still creating... [10s elapsed]
libvirt_volume.debian-qcow2: Creation complete after 11s [id=/srv/terraform-provider-libvirt-pool-debian/debian-qcow2]
libvirt_volume.disk_debian_resized: Creating...
libvirt_cloudinit_disk.commoninit: Creation complete after 11s [id=/srv/terraform-provider-libvirt-pool-debian/commoninit.iso;5e9f02e4-631b-5c20-ed09-64bed861e1a0]
libvirt_volume.disk_debian_resized: Creation complete after 0s [id=/srv/terraform-provider-libvirt-pool-debian/disk]
libvirt_domain.domain-debian: Creating...
libvirt_domain.domain-debian: Still creating... [10s elapsed]
libvirt_domain.domain-debian: Still creating... [20s elapsed]
...
libvirt_domain.domain-debian: Still creating... [5m0s elapsed]

Error: Error: couldn't retrieve IP address of domain.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)

  on debian10.tf line 36, in resource "libvirt_domain" "domain-debian":
  36: resource "libvirt_domain" "domain-debian" {
virsh qemu-agent-command debian-terraform '{"execute":"guest-network-get-interfaces"}'|jq '.return[1]."ip-addresses"[0]."ip-address"'| sed 's/\"//g'

Give me : 192.168.1.26

terraform refresh

Give me : Outputs:

ips = [
  [],
]

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 31 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Yes I did it changing timeout in code, I’ll send my PR to close it!

MinTimeout:  1 * time.Minute,
Delay:        30 * time.Second, // Wait this time before starting checks
Timeout:     5 * time.Minute,
libvirt_domain.domain-debian: Creation complete after 2m30s [id=f0d1a0c8-322d-4585-a61f-7474a4ce4a0d]

Apply complete! Resources: 5 added, 0 changed, 0 destroyed.

Outputs:

ips = [
  [
    "192.168.1.20",
    "fe80::5054:ff:fe56:2230",
  ],
]

Yeah in Ubuntu it’s the same and that’s why I’ve this in my cloud_init.cfg:

packages:
  - qemu-guest-agent

runcmd:
  - [ systemctl, daemon-reload ]
  - [ systemctl, enable, qemu-guest-agent ]
  - [ systemctl, start, qemu-guest-agent ]```

huuumm, so Huston we have a problem with qemu-agent when it first request ip address?

yeah that’s what seems to me