5

I have a vagrantfile using a box on top of virtualbox with a provision script.

Now I am trying to use packer to output a box already after provision.

However I cannot find a builder to use the ".box" file I already have. What am I doing wrong?

guy mograbi
  • 27,391
  • 16
  • 83
  • 122

3 Answers3

3

I just got a solution to this tiny little problem (convert a vagrant .box file to .ova for use by packer):

  • Create a vm using the .box file as a base. I use this Vagrantfile, with box opscode-centos-7.0:
    $provisioning_script = <<PROVISIONING_SCRIPT
    adduser packer
    echo "packer" | passwd packer --stdin
    echo "packer ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/packer
    PROVISIONING_SCRIPT

    Vagrant.configure(2) do |config|
      config.vm.box = "opscode-centos-7.0"
      config.ssh.insert_key = false
      config.vm.provider "virtualbox" do |v|
        v.name = "packer-base"
      end
      config.vm.provision :shell, inline: $provisioning_script
    end
  • run vagrant up
  • run vagrant halt
  • run vboxmanage export --ovf20 -o packer-base.ova packer-base
  • run vagrant destroy

This also creates the packer user with a default password so that packer can easily connect to the instance to do stuff. Also note the insert_key parameter that will prevent replacing the vagrant default insecure key with a secure one and allow subsequent vagrant setups to properly connect via SSH to the new images (after packer is done).

tazmanos
  • 313
  • 2
  • 9
0

Packer out-of-the-box doesn't support using Vagrant boxes as input (yet).

But there is a custom plugin, see this comment.

Basil Peace
  • 124
  • 13
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link answers can become invalid if the linked page changes. – Daniel Puiu Aug 15 '18 at 14:54
-1

If you want to build a vagrant box that runs with provider virtualbox, have a look here.

However, it takes an iso or ovf as input, not a vagrant box.

Have a look at these templates to get you started using the virtualbox builder with packer.

Make sure your run the post-processor to convert the virtualbox vm into a vagrant box.

mkd
  • 79
  • 1
  • 6