Search code examples
virtualboxpacker

Packer - 1st: How to create a file in the machine. 2nd: Export machine to ova file


I use Packer to create a template file which is deployed via API to our provider.

The template is built from CentOS 7.4 minimal ISO file, using a kickstart anaconda-ks.cfg.

In that kickstart file I'm configuring what packages to install in my template and in the post-config part of the kickstart file I run different bash commands to configure it. On this post-config I also run a few cat > /path/file.sh <<EOF to put some files on disk.

1st.

One of the files is quite large and although I've tried with splitting it in pieces, one last piece freeze the template creation. I can see nothing wrong in my code. Seems to me like the last cat >> /path/file.sh <<EOF just freezes Packer job.

The question is if there is any method like in Terraform to use a template file somewhere in the Packer directory structure that will be used as a source to create that /path/file.sh file in my template.

2nd.

When the template is finished I need to export it to an .ova file, because my provider does not accept any other file type.

As in my json file I'm using builder type virtualbox-iso and post-processors type vagrant, I'm wondering how can I do the last part - to export to ova.

My first thought was to use ovftool, but as I'm new to packer I do not know how to insert that in my Packer code.

Please help.

Thank you.


Solution

    1. Use the file provisioner
    2. Set "format": "ova" in your template and remove the vagrant post-processor unless you need a vagrant box too. *) See virtualbox-iso: format

    *) If you really need that you should run a shell-local post-provisioner in parallel with the vagrant one that converts the ovf to ova instead of setting format, since most likely the vagrant box must contain an ovf.