guy mograbi
guy mograbi

Reputation: 28608

How to use packer with box file?

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?

Upvotes: 5

Views: 1867

Answers (3)

Basil Peace
Basil Peace

Reputation: 412

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

But there is a custom plugin, see this comment.

Upvotes: 0

tazmanos
tazmanos

Reputation: 313

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).

Upvotes: 3

mkd
mkd

Reputation: 79

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.

Upvotes: -1

Related Questions