A Packer template for creating a Fortinet FortiGate Vagrant box for the libvirt provider.
0. Verify the prerequisite tools are installed.
$ which git unzip packer libvirtd qemu-system-x86_64 vagrant $ vagrant plugin list vagrant-libvirt (0.4.0, global)
1. Log in and download the FortiGate-VM virtual appliance deployment package from Fortinet. Save the file to your Downloads
directory.
2. Extract the disk image file to the /var/lib/libvirt/images
directory.
$ cd $HOME/Downloads $ sudo unzip -d /var/lib/libvirt/images FGT_VM64_KVM-v6-build1828-FORTINET.out.kvm.zip
3. Modify the file ownership and permissions. Note the owner may differ between Linux distributions.
Ubuntu 18.04
$ sudo chown libvirt-qemu:kvm /var/lib/libvirt/images/fortios.qcow2 $ sudo chmod u+x /var/lib/libvirt/images/fortios.qcow2
Arch Linux
$ sudo chown nobody:kvm /var/lib/libvirt/images/fortios.qcow2 $ sudo chmod u+x /var/lib/libvirt/images/fortios.qcow2
4. Create the boxes
directory.
$ mkdir -p $HOME/boxes
5. Clone this GitHub repo and cd into the directory.
$ git clone https://github.com/mweisel/fortigate-vagrant-libvirt $ cd fortigate-vagrant-libvirt
6. Packer build to create the Vagrant box artifact. Supply the FortiOS version number for the version
variable value.
$ packer build -var 'version=6.4.5' fortigate.pkr.hcl
7. Copy the Vagrant box artifact to the boxes
directory.
$ cp ./builds/fortinet-fortigate-6.4.5.box $HOME/boxes/
8. Copy the box metadata file to the boxes
directory.
$ cp ./src/fortigate.json $HOME/boxes/
9. Change the current working directory to boxes
.
$ cd $HOME/boxes
10. Substitute the HOME
placeholder string in the box metadata file.
$ awk '/url/{gsub(/^ */,"");print}' fortigate.json "url": "file://HOME/boxes/fortinet-fortigate-VER.box" $ sed -i "s|HOME|${HOME}|" fortigate.json $ awk '/url/{gsub(/^ */,"");print}' fortigate.json "url": "file:///home/marc/boxes/fortinet-fortigate-VER.box"
11. Also, substitute the VER
placeholder string with the FortiOS version you're using.
$ awk '/VER/{gsub(/^ */,"");print}' fortigate.json "version": "VER", "url": "file:///home/marc/boxes/fortinet-fortigate-VER.box" $ sed -i 's/VER/6.4.5/g' fortigate.json $ awk '/\<version\>|url/{gsub(/^ */,"");print}' fortigate.json "version": "6.4.5", "url": "file:///home/marc/boxes/fortinet-fortigate-6.4.5.box"
12. Add the Vagrant box to the local inventory.
$ vagrant box add fortigate.json
This project is licensed under the MIT License - see the LICENSE file for details