Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use packer with box file?

Tags:

vagrant

packer

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?

like image 655
guy mograbi Avatar asked Oct 31 '22 08:10

guy mograbi


1 Answers

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

like image 151
tazmanos Avatar answered Nov 09 '22 11:11

tazmanos