使用在 vagrant-libvirt 上运行的加壳器构建一个盒子

使用在 vagrant-libvirt 上运行的加壳器构建一个盒子

我想构建一个 Debian 扩展,以便通过 libvirt 提供程序在 vagrant 上运行。

我尝试过从头开始构建,也尝试过使用加壳器构建,最好的结果是重新启动时出现“操作系统未找到”错误,或者盒子的流浪状态冻结。

什么时候不是使用 packer,我可以在 virt-manager 内启动盒子,它可以工作,但如果我在同一个盒子上执行 vagrant up,它就无法获得网络访问权限。 Packer 应该简化这一点,但我得到了没有找到媒体启动时出错。

使用 Vagrant 启动它会冻结在以下位置:

默认:等待域获取 IP 地址。

如果我随后通过以下方式连接到机器的屏幕,virt-manager我会看到它冻结:

acpid:等待事件:事件日志记录已关闭

我哪里错了?

这个加壳脚本输出后是否需要额外的手动步骤?

这是我使用的打包模板:

{

"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"
    }
]

}

以及用于启动它的 Vagrant 文件:

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

进一步调查发现 MAC 地址存在以下不匹配情况:

  • 在启动的映像内部(通过 virt-manager 访问):52:54:00:a0:46:68
  • 在 Vagrant 中(来自调试输出): mac="52:54:00:9e:ad:85"
  • 并从错误消息中: DEBUG wait_till_up: 正在搜索 IP for MAC 地址: 52:54:00:b8:88:7d

此外,域的 UUID 也不相同:

  • Vagrant 给出: id="24e1487f-c36f-4cc3-a45e-4d8c6d867a4d"
  • virt-manager 报告:c4d152fd-6da4-4b09-bb98-96767b367a6c

什么可能导致不匹配?

相关内容