2

I would like to build a debian stretch to run on vagrant with the libvirt provider.

I have tried building from scratch and also with packer and the best I get is a OS not found error on the reboot or a freeze on the vagrant up of the box.

When not using packer I can boot the box inside virt-manager and it works but it gets no network access if I do a vagrant up on the same box. Packer is supposed to simplify that but I get a no media found error at boot.

Booting with Vagrant up it freezes at the point of ==> default: Waiting for domain to get an IP address..

If I then attach to the screen of the machine through /virt-manager/ I see it frozen after

acpid: waiting for events: event logging is off

Where am I going wrong?

Is there need for an extra manual step after the output of this packer script.

Here is the packer template I use

{
"variables": {
    "user": "vagrant",
    "password": "vagrant",
    "disk_size": "100000",
    "domain": ""
},

"builders": [
    {
        "name": "debian93-vagrant",

        "type": "qemu",
        "format": "qcow2",
        "accelerator": "kvm",
        "disk_size": "{{ user `disk_size` }}",
    "iso_url": "https://cdimage.debian.org/debian-cd/9.3.0/amd64/iso-cd/debian-9.3.0-amd64-netinst.iso",
        "iso_checksum": "83480be837710a76fd4e75a6573ca110e06f5a7589d2d3852bdb0f45749800b3",
        "iso_checksum_type": "sha256",

        "http_directory": "http",

        "ssh_username": "{{ user `user` }}",
        "ssh_password": "{{ user `password` }}",
        "shutdown_command": "echo '{{ user `password` }}' | sudo -S shutdown -h now",

        "ssh_wait_timeout": "60m",

        "boot_wait": "2s",
        "boot_command": [
               "<esc><wait><wait>",
               "install ",

               "auto=true ",
               "priority=critical ",
               "interface=auto ",
               "url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg ",

               "passwd/user-fullname={{ user `user` }} ",
               "passwd/user-password={{ user `password` }} ",
               "passwd/user-password-again={{ user `password` }} ",
               "passwd/username={{ user `user` }} ",

               "<enter>"
        ]
    }
],

"provisioners": [
    {
        "type": "shell",
        "execute_command": "echo '{{ user `password` }}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'",
        "scripts": [
            "scripts/vagrant.sh",
            "scripts/update.sh",
            "scripts/packages.sh",
            "scripts/cleanup.sh"
        ]
    }
],

    "post-processors": [
    {
        "keep_input_artifact": false,
        "output": "box/debian93-vagrant.box",
        "type": "vagrant"
    }
]

}

And the Vagrant file to boot it up

ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt'

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
   # TODO build our own and deploy it to vagrantboxes
   # config.vm.box = "debian/jessie64"
   config.vm.box = "debian93Vagrant"
   # config.vm.box = ""
   #config.vm.box_version = "0.0.1"

   # Remove or adapt host_ip if remote access is required
   config.vm.network "forwarded_port", guest: 5601, host: 5601, host_ip:    "127.0.0.1"
   config.vm.network "forwarded_port", guest: 9200, host: 9200, host_ip: "127.0.0.1"
   config.vm.network "forwarded_port", guest: 5044, host: 5044, host_ip: "127.0.0.1"

   # Create a private network, which allows host-only access to the machine
   # using a specific IP.
   config.vm.network "private_network", ip: "192.168.121.10"

   # Create a public network, which generally matched to bridged network.
   # Bridged networks make the machine appear as another physical device on
   # your network.
   # config.vm.network "public_network"

   # If more folders are needed map them here
   # config.vm.synced_folder ".", "/vagrant"


   config.vm.synced_folder "./config", "/config"

   # Libvirt provider with added oomph
   config.vm.provider :libvirt do |prov|
          prov.memory = 4096 
          prov.cpus = 4
   end

   # Basic setup through a shell provisioner
   config.vm.provision "shell", inline: <<-SHELL
        apt-get update
        apt-get upgrade -y
        apt-get install net-tools htop
        sleep 5
  SHELL

  # Deploy the stack
  config.vm.provision "ansible" do |an|
        an.playbook = "./ansible/single_machine.yml"
  end

  # Leave things running permanently post installation
  config.vm.provision "shell", inline: <<-SHELL
    systemctl enable logstash 
    systemctl enable elasticsearch 
    systemctl enable kibana
    service kibana start
    service elasticsearch start
    service logstash start
 SHELL

end

Further investigation reveals the following mismatch in the MAC addresses Inside the booted image (accessed through virt-manager): 52:54:00:a0:46:68 In Vagrant (from debug output): mac="52:54:00:9e:ad:85" And from the error message: DEBUG wait_till_up: Searching for IP for MAC address: 52:54:00:b8:88:7d

Also the UUIDs of the domains are not the same: Vagrant gives: id="24e1487f-c36f-4cc3-a45e-4d8c6d867a4d" virt-manager reports: c4d152fd-6da4-4b09-bb98-96767b367a6c

What could cause the mismatch?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.