vagrant-libvirt / vagrant-libvirt

Vagrant provider for libvirt.
https://vagrant-libvirt.github.io/vagrant-libvirt/
MIT License
2.33k stars 500 forks source link

"private_network", type: "dhcp" raises an error #427

Closed wwentland closed 9 years ago

wwentland commented 9 years ago

Hi, I use the following Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  config.vm.box = "debian-jessie"
  config.vm.network "private_network", type: "dhcp"

  config.vm.define :jessiebox do |jessiebox|
    jessiebox.vm.hostname = "debian-jessie.test"
  end
end

#  -*- mode: ruby -*-
# vi: set ft=ruby :

which results in the following error:

$ vagrant up --provider=libvirt
Bringing machine 'jessiebox' up with 'libvirt' provider...
==> jessiebox: Creating image (snapshot of base box volume).
==> jessiebox: Creating domain with the following settings...
==> jessiebox:  -- Name:              jessie_jessiebox
==> jessiebox:  -- Domain type:       kvm
==> jessiebox:  -- Cpus:              1
==> jessiebox:  -- Memory:            512M
==> jessiebox:  -- Base box:          debian-jessie
==> jessiebox:  -- Storage pool:      default
==> jessiebox:  -- Image:             /var/lib/libvirt/images/jessie_jessiebox.img
==> jessiebox:  -- Volume Cache:      default
==> jessiebox:  -- Kernel:            
==> jessiebox:  -- Initrd:            
==> jessiebox:  -- Graphics Type:     vnc
==> jessiebox:  -- Graphics Port:     5900
==> jessiebox:  -- Graphics IP:       127.0.0.1
==> jessiebox:  -- Graphics Password: Not defined
==> jessiebox:  -- Video Type:        cirrus
==> jessiebox:  -- Video VRAM:        9216
==> jessiebox:  -- Keymap:            en-us
==> jessiebox:  -- Command line : 
==> jessiebox: Creating shared folders metadata...
Error while setting up autostart on network: undefined method `autostart=' for nil:NilClass.

I'd like to use this so that I can use the same Vagrantfile for both Virtualbox and libvirt/qemu and have to set it as Virtualbox requires it for NFS (cf. http://docs.vagrantup.com/v2/synced-folders/nfs.html → Prerequisites).

Versions in question are:

$ vagrant plugin list
landrush (0.15.3)
vagrant-libvirt (0.0.30)
vagrant-share (1.1.4, system)

The debian-jessie box is built using packer using the following configuration:

$ cat debian-jessie-amd64.json 
{
    "variables": {
    "cpus": "1",
    "http_dir": "http",
    "iso_checksum": "22bae271a732333ebff150598292d9907d2c6001",
    "iso_checksum_type": "sha1",
    "iso_url": "http://cdimage.debian.org/debian-cd/8.1.0/amd64/iso-cd/debian-8.1.0-amd64-CD-1.iso",
    "memory": "384",
    "ssh_password": "vagrant",
    "ssh_username": "vagrant",
    "vm_name": "debian-jessie",
    "vm_domain": "vagrant"
    },
    "builders":
    [
    {
        "type": "virtualbox-iso",
        "guest_os_type": "Debian_64",
        "iso_url": "{{user `iso_url`}}",
        "iso_checksum": "{{user `iso_checksum`}}",
        "iso_checksum_type": "{{user `iso_checksum_type`}}",
        "http_directory": "{{user `http_dir`}}",
        "boot_wait": "2s",
        "boot_command":
        [
        "<esc><esc><wait><esc><wait>",
        "install <wait>",
        "auto ",
        "preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/debian/8/preseed.cfg ",
        "debian-installer=en_GB ",
        "locale=en_GB ",
        "kbd-chooser/method=gb ",
        "keyboard-configuration/xkb-keymap=gb ",
        "netcfg/get_hostname={{user `vm_name`}} ",
        "netcfg/get_domain={{user `vm_domain`}} ",
        "fb=false ",
        "debconf/frontend=noninteractive ",
        "console-setup/ask_detect=false ",
        "console-keymaps-at/keymap=gb ",
        "<enter>"
        ],
        "ssh_username": "{{user `ssh_username`}}",
        "ssh_password": "{{user `ssh_password`}}",
        "headless": true,
        "vboxmanage": [
        [ "modifyvm", "{{.Name}}", "--memory", "{{user `memory`}}" ],
        [ "modifyvm", "{{.Name}}", "--cpus", "{{user `cpus`}}" ]
        ],
        "shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
        "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso"

    },
    {
        "type": "qemu",
        "iso_url": "{{user `iso_url`}}",
        "iso_checksum": "{{user `iso_checksum`}}",
        "iso_checksum_type": "{{user `iso_checksum_type`}}",
        "output_directory": "{{user `vm_name`}}-qemu",
        "ssh_wait_timeout": "30s",
        "shutdown_command": "echo 'vagrant'|sudo -S shutdown -h now",
        "disk_size": 5000,
        "format": "qcow2",
        "headless": false,
        "accelerator": "kvm",
        "http_directory": "http",
        "ssh_username": "vagrant",
        "ssh_password": "vagrant",
        "ssh_port": 22,
        "ssh_wait_timeout": "90m",
        "vm_name": "{{user `vm_name`}}",
        "net_device": "virtio-net",
        "qemuargs": [ [ "-m", "{{user `memory`}}" ] ],
        "disk_interface": "virtio",
        "boot_wait": "2s",
        "boot_command":
        [
        "<esc> ",
        "install ",
        "auto ",
        "url=http://{{.HTTPIP}}:{{.HTTPPort}}/debian/8/preseed.cfg ",
        "debian-installer=en_GB ",
        "locale=en_GB ",
        "kbd-chooser/method=gb ",
        "keyboard-configuration/xkb-keymap=gb ",
        "netcfg/get_hostname={{user `vm_name`}} ",
        "netcfg/get_domain={{user `vm_domain`}} ",
        "fb=false ",
        "debconf/frontend=noninteractive ",
        "console-setup/ask_detect=false ",
        "console-keymaps-at/keymap=gb ",
        "<enter>"
        ]
    }
    ],
    "post-processors": [
    {
        "type": "vagrant",
        "output": "./builds/{{.Provider}}/{{user `vm_name`}}.box"
    }
    ],
    "provisioners": [
    {
        "type": "shell",
        "only": ["virtualbox-iso"],
        "execute_command": "echo 'vagrant'|{{.Vars}} sudo -E -S bash '{{.Path}}'",
        "scripts": [
        "provisioner/bash/vbox/guest_additions.sh"
        ]
    },
    {
        "type": "shell",
        "execute_command": "echo 'vagrant'|{{.Vars}} sudo -E -S bash '{{.Path}}'",
        "scripts": [
        "provisioner/bash/common/sshd.sh",
        "provisioner/bash/common/vagrant.sh",
        "provisioner/bash/debian/sudoers.sh",
        "provisioner/bash/debian/nfs.sh"
        ]
    }
    ]
}

$ $ cat http/debian/8/preseed.cfg 
d-i localechooser/supported-locales multiselect en_GB.UTF-8, en_US.UTF-8, de_DE.UTF-8

### Always load firmware
d-i hw-detect/load_firmware boolean true

### apt configuration
d-i mirror/country string manual
d-i mirror/http/hostname string httpredir.debian.org
d-i mirror/http/directory string /debian
d-i mirror/http/proxy string
apt-mirror-setup apt-setup/use_mirror boolean true
apt-cdrom-setup apt-setup/cdrom/set-first boolean false
d-i preseed/late_command string sed -i '/^deb cdrom:/s/^/#/' /target/etc/apt/sources.list
d-i preseed/early_command string sed -i \
  '/in-target/idiscover(){/sbin/discover|grep -v VirtualBox;}' \
  /usr/lib/pre-pkgsel.d/20install-hwpackages

### Account setup
d-i passwd/root-password password vagrant
d-i passwd/root-password-again password vagrant

d-i passwd/user-fullname string vagrant
d-i passwd/username string vagrant
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/user-default-groups string sudo adm

### Clock and time zone setup
d-i clock-setup/utc boolean true
d-i time/zone string Europe/Berlin
d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server de.pool.ntp.org

### Verbose output and no boot splash screen.
d-i debian-installer/quiet  boolean false
d-i debian-installer/splash boolean false

### Partitioning
d-i partman-auto/method string lvm
d-i partman-auto/choose_recipe select atomic
d-i partman-md/device_remove_md boolean false
d-i partman-lvm/device_remove_lvm boolean fals
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true

### Package selection
tasksel tasksel/first multiselect standard
d-i pkgsel/include string openssh-server vim sudo
d-i pkgsel/upgrade select safe-upgrade
popularity-contest popularity-contest/participate boolean false

### grub configuration
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i grub-installer/bootdev string default

### Finishing up the installation
# During installations from serial console, the regular virtual consoles
# (VT1-VT6) are normally disabled in /etc/inittab. Uncomment the next
# line to prevent this.
d-i finish-install/keep-consoles boolean true

# Avoid that last message about the install being complete.
d-i finish-install/reboot_in_progress note

I am not sure if config.vm.network "private_network", type: "dhcp" is supposed to work at all though.

Thank you for your outstanding work on this plugin!

bexelbie commented 9 years ago

reproduced with CentOS

jpeeler commented 9 years ago

I'm running into this on Fedora 22 as well. It appears from the documentation that using DHCP is set up by default, but the configuration uses a different syntax: https://github.com/pradels/vagrant-libvirt#networks. Still investigating...