Using packer to build a Vagrant box

Background

So, Oracle Linux 7.4 was just released. Previously when a new version was released I downloaded it and manually installed it to see what the fuss was about (and to make sure you could actually install Oracle on it).

These days I tend to use Vagrant (as written about previously). But how do you build a Vagrant box?
You could of course do it the manual way, which means you click through the installation of the OS, then customize it to your hearts desire and finally export the VM as a Vagrant box, and that is fine. But as with all manual tasks, it gets tedious after a while.
I also tend to make the box look sort of the same every time (with the same extra packages installed and whatnot), so how do you easily automate this process?

Enter Packer, a tool to ‘Build Automated Machine Images’, as the slogan goes. Packer is built by Hashicorp (who also built Vagrant, Terraform and bunch of other awesome tools), and it helps you create identical images for a variety of different platforms using the same source configuration.

The source configuration in this case is a json file, which describes the builder (Virtualbox, Vmware, Amazon ec2 etc), and also have different types of provisioners that can be called (shell, Ansible, Chef, Puppet, Powershell) to further customize the image.

How?

This post is not going to be a deep-dive into Packer, but rather a quick example on how to build your own image.

In this case I’m using the virtualbox-iso builder, which means I will use the Oracle Linux ISO as the source of the installation, kickstart will be used as the means of doing the OS installation, and then I’ll use the shell provisioner to install some extra packages. The provisioning step could easily be replaced by Ansible (or your tool of choice).
The kickstart config can be as elaborate as you choose it to be, but a good starting point is to just use the file that gets created as part of the manual installation.

So these are the files that will be used:

$ tree
|-- http
| `-- ol74-ks.cfg      <-- Kickstart file
|-- ol74-x64.iso
|-- packer-ol74.json   <-- source configuration

 

This is the content of  http/ol74-ks.cfg

# platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
install

# Firewall configuration
firewall --disabled

# Keyboard layouts
#keyboard --vckeymap='us' --xlayouts='us'
keyboard sv-latin1

# Reboot after installation
reboot

# Root password
rootpw root

# System timezone
timezone Europe/Stockholm

# System language
lang en_US.UTF-8

cdrom
# Network information
network --bootproto=dhcp --device=p2p1 --onboot=on --ipv6=auto --activate

# System authorization information
auth --useshadow --passalgo=sha512

# Use text mode install
text

# SELinux configuration
selinux --disabled

# Do not configure the X Window System
skipx

bootloader --location=mbr --boot-drive=sda

# Partition clearing information
clearpart --all --initlabel

autopart --type=xfs
%packages --nobase
@core
man
yum-plugin-security
openssh-clients
make
gcc
btrfs-progs
wget
unzip
ntp
bzip2
kernel-uek-devel
net-tools
%end

%post
%end

 

This is the actual configuration file that will be used to build the image:

$ cat packer-ol74.json

 "variables": {
        "ssh_name": "root",
        "ssh_pass": "root",
        "hostname": "ol74",
       "outputfile": "ol74.box",
       "compression" : "6"
   },
    "builders": [{
        "type": "virtualbox-iso",
        "guest_os_type": "Oracle_64",
        "guest_additions_url": "",
        "guest_additions_sha256": "",
        "guest_additions_path": "",
       "guest_additions_mode": "upload",
       "output_directory": "output-{{user `hostname`}}",
        "vm_name": "packer-{{user `hostname`}}",
        "vboxmanage": [
           ["modifyvm", "{{.Name}}", "--vram", "32"],
           ["modifyvm", "{{.Name}}", "--memory", "1024"] ,
           ["modifyvm", "{{.Name}}", "--cpus", "1"]
 ],
 "hard_drive_interface" : "sata",
 "disk_size": 50000,
       "headless" : 0,
        "iso_url": "/Users/miksan/downloads/iso/ol74-x64.iso",
        "iso_checksum": "298724f8eaa0dbf961c608c4965be70e",
        "iso_checksum_type": "md5",
        "http_directory" : "http",
        "http_port_min" : 8080,
        "http_port_max" : 8082,
        "ssh_username": "{{user `ssh_name`}}",
        "ssh_password": "{{user `ssh_pass`}}",
        "ssh_wait_timeout": "30m",
        "shutdown_command": "shutdown -h now",
        "shutdown_timeout": "40m",
 "boot_wait": "5s",
        "boot_command" : [
            "<tab>",
            " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks-ol74.cfg ",
            "<enter>"
        ]
    }],
  "provisioners"             : [{
    "type": "shell",
    "execute_command": "sh '{{ .Path }}'",
    "inline": [
      "yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y",
      "yum install ansible -y",
      "mkdir -p /media/dvd",
      "mount -o loop VBoxGuestAdditions*.iso /media/dvd",
      "sh /media/dvd/VBoxLinuxAdditions.run --nox11",
      "umount /media/dvd",
      "rm VBoxGuestAdditions*.iso",
      "useradd vagrant",
      "chpasswd <<<\"vagrant:vagrant\"",
      "cp /etc/sudoers /etc/sudoers.orig",
      "sed -i -e 's/Defaults\\s*requiretty$/#Defaults\trequiretty/' /etc/sudoers",
      "sed -i -e '/# %wheel\tALL=(ALL)\tNOPASSWD: ALL/a %vagrant\tALL=(ALL)\tNOPASSWD: ALL' /etc/sudoers",
      "mkdir ~vagrant/.ssh",
      "chmod 700 ~vagrant/.ssh",
      "echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key' > ~vagrant/.ssh/authorized_keys",
      "chmod 600 ~vagrant/.ssh/authorized_keys",
      "chown -R vagrant: ~vagrant/.ssh",
      "dd if=/dev/zero of=/root/tempfile bs=1M; rm -f /root/tempfile",
      ]
  }],
  "post-processors": [
    {
      "type": "vagrant",
      "output": "{{user `outputfile`}}",
      "compression_level": "{{user `compression`}}"
    }
  ]
}

The shell provisioner can also be run as one or more scripts instead of inline, like in this example.

$ packer validate packer-ol74.json <-- Make sure the source configuration is ok.
Template validated sucessfully.
 
$ packer build packer-ol74.json    <-- Build the image
virtualbox-iso output will be in this color.

==> virtualbox-iso: Downloading or copying Guest additions
 virtualbox-iso: Downloading or copying: file:///Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso
==> virtualbox-iso: Downloading or copying ISO
 virtualbox-iso: Downloading or copying: file:///Users/miksan/downloads/iso/ol74-x64.iso
==> virtualbox-iso: Starting HTTP server on port 8080
==> virtualbox-iso: Creating virtual machine...
==> virtualbox-iso: Creating hard drive...
==> virtualbox-iso: Creating forwarded port mapping for SSH (host port 3839)
==> virtualbox-iso: Executing custom VBoxManage commands...
 virtualbox-iso: Executing: modifyvm packer-ol74 --vram 32
 virtualbox-iso: Executing: modifyvm packer-ol74 --memory 1024
 virtualbox-iso: Executing: modifyvm packer-ol74 --cpus 1
==> virtualbox-iso: Starting the virtual machine...
==> virtualbox-iso: Waiting 5s for boot...
==> virtualbox-iso: Typing the boot command...
==> virtualbox-iso: Waiting for SSH to become available...
==> virtualbox-iso: Connected to SSH!
==> virtualbox-iso: Uploading VirtualBox version info (5.1.26)
==> virtualbox-iso: Uploading VirtualBox guest additions ISO...
==> virtualbox-iso: Provisioning with shell script: /var/folders/8j/n9jpngw1629gbmg1c01c8frd26n66t/T/packer-shell058067119
 virtualbox-iso: Loaded plugins: ulninfo
 virtualbox-iso: Examining /var/tmp/yum-root-a7nT8o/epel-release-latest-7.noarch.rpm: epel-release-7-10.noarch
 virtualbox-iso: Marking /var/tmp/yum-root-a7nT8o/epel-release-latest-7.noarch.rpm to be installed
 virtualbox-iso: Resolving Dependencies
 virtualbox-iso: --> Running transaction check
 virtualbox-iso: ---> Package epel-release.noarch 0:7-10 will be installed
 virtualbox-iso: --> Finished Dependency Resolution
 virtualbox-iso:
 virtualbox-iso: Dependencies Resolved
 virtualbox-iso:
 virtualbox-iso: ================================================================================
 virtualbox-iso: Package Arch Version Repository Size
 virtualbox-iso: ================================================================================
 virtualbox-iso: Installing:
 virtualbox-iso: epel-release noarch 7-10 /epel-release-latest-7.noarch 24 k
 virtualbox-iso:
 virtualbox-iso: Transaction Summary
 virtualbox-iso: ================================================================================
 virtualbox-iso: Install 1 Package
 virtualbox-iso:
 virtualbox-iso: Total size: 24 k
 virtualbox-iso: Installed size: 24 k
 virtualbox-iso: Downloading packages:
 virtualbox-iso: Running transaction check
 virtualbox-iso: Running transaction test
 virtualbox-iso: Transaction test succeeded
 virtualbox-iso: Running transaction
 virtualbox-iso: Installing : epel-release-7-10.noarch 1/1
 virtualbox-iso: Verifying : epel-release-7-10.noarch 1/1
 virtualbox-iso:
 virtualbox-iso: Installed:
 virtualbox-iso: epel-release.noarch 0:7-10
 virtualbox-iso:
 virtualbox-iso: Complete!
 virtualbox-iso: Loaded plugins: ulninfo
 virtualbox-iso: Resolving Dependencies
 virtualbox-iso: --> Running transaction check
 virtualbox-iso: ---> Package ansible.noarch 0:2.3.1.0-1.el7 will be installed
 virtualbox-iso: --> Processing Dependency: sshpass for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-six for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-setuptools for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-paramiko for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-keyczar for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-jinja2 for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-httplib2 for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-crypto for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Processing Dependency: PyYAML for package: ansible-2.3.1.0-1.el7.noarch
 virtualbox-iso: --> Running transaction check
 virtualbox-iso: ---> Package PyYAML.x86_64 0:3.10-11.el7 will be installed
 virtualbox-iso: --> Processing Dependency: libyaml-0.so.2()(64bit) for package: PyYAML-3.10-11.el7.x86_64
 virtualbox-iso: ---> Package python-httplib2.noarch 0:0.7.7-3.el7 will be installed
 virtualbox-iso: ---> Package python-jinja2.noarch 0:2.7.2-2.el7 will be installed
 virtualbox-iso: --> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-2.el7.noarch
 virtualbox-iso: --> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-2.el7.noarch
 virtualbox-iso: ---> Package python-keyczar.noarch 0:0.71c-2.el7 will be installed
 virtualbox-iso: --> Processing Dependency: python-pyasn1 for package: python-keyczar-0.71c-2.el7.noarch
 virtualbox-iso: ---> Package python-setuptools.noarch 0:0.9.8-7.el7 will be installed
 virtualbox-iso: --> Processing Dependency: python-backports-ssl_match_hostname for package: python-setuptools-0.9.8-7.el7.noarch
 virtualbox-iso: ---> Package python-six.noarch 0:1.9.0-2.el7 will be installed
 virtualbox-iso: ---> Package python2-crypto.x86_64 0:2.6.1-13.el7 will be installed
 virtualbox-iso: --> Processing Dependency: libtomcrypt.so.0()(64bit) for package: python2-crypto-2.6.1-13.el7.x86_64
 virtualbox-iso: ---> Package python2-paramiko.noarch 0:1.16.1-2.el7 will be installed
 virtualbox-iso: --> Processing Dependency: python2-ecdsa for package: python2-paramiko-1.16.1-2.el7.noarch
 virtualbox-iso: ---> Package sshpass.x86_64 0:1.06-1.el7 will be installed
 virtualbox-iso: --> Running transaction check
 virtualbox-iso: ---> Package libtomcrypt.x86_64 0:1.17-25.el7 will be installed
 virtualbox-iso: --> Processing Dependency: libtommath >= 0.42.0 for package: libtomcrypt-1.17-25.el7.x86_64
 virtualbox-iso: --> Processing Dependency: libtommath.so.0()(64bit) for package: libtomcrypt-1.17-25.el7.x86_64
 virtualbox-iso: ---> Package libyaml.x86_64 0:0.1.4-11.el7_0 will be installed
 virtualbox-iso: ---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
 virtualbox-iso: ---> Package python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7 will be installed
 virtualbox-iso: --> Processing Dependency: python-backports for package: python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch
 virtualbox-iso: ---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
 virtualbox-iso: ---> Package python2-ecdsa.noarch 0:0.13-4.el7 will be installed
 virtualbox-iso: ---> Package python2-pyasn1.noarch 0:0.1.9-7.el7 will be installed
 virtualbox-iso: --> Running transaction check
 virtualbox-iso: ---> Package libtommath.x86_64 0:0.42.0-5.el7 will be installed
 virtualbox-iso: ---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
 virtualbox-iso: --> Finished Dependency Resolution
 virtualbox-iso:
 virtualbox-iso: Dependencies Resolved
 virtualbox-iso:
 virtualbox-iso: ================================================================================
 virtualbox-iso: Package Arch Version Repository Size
 virtualbox-iso: ================================================================================
 virtualbox-iso: Installing:
 virtualbox-iso: ansible noarch 2.3.1.0-1.el7 epel 5.7 M
 virtualbox-iso: Installing for dependencies:
 virtualbox-iso: PyYAML x86_64 3.10-11.el7 ol7_latest 153 k
 virtualbox-iso: libtomcrypt x86_64 1.17-25.el7 epel 225 k
 virtualbox-iso: libtommath x86_64 0.42.0-5.el7 epel 35 k
 virtualbox-iso: libyaml x86_64 0.1.4-11.el7_0 ol7_latest 54 k
 virtualbox-iso: python-babel noarch 0.9.6-8.el7 ol7_latest 1.4 M
 virtualbox-iso: python-backports x86_64 1.0-8.el7 ol7_latest 5.2 k
 virtualbox-iso: python-backports-ssl_match_hostname noarch 3.4.0.2-4.el7 ol7_latest 11 k
 virtualbox-iso: python-httplib2 noarch 0.7.7-3.el7 epel 70 k
 virtualbox-iso: python-jinja2 noarch 2.7.2-2.el7 ol7_latest 515 k
 virtualbox-iso: python-keyczar noarch 0.71c-2.el7 epel 218 k
 virtualbox-iso: python-markupsafe x86_64 0.11-10.el7 ol7_latest 25 k
 virtualbox-iso: python-setuptools noarch 0.9.8-7.el7 ol7_latest 397 k
 virtualbox-iso: python-six noarch 1.9.0-2.el7 ol7_latest 28 k
 virtualbox-iso: python2-crypto x86_64 2.6.1-13.el7 epel 476 k
 virtualbox-iso: python2-ecdsa noarch 0.13-4.el7 epel 83 k
 virtualbox-iso: python2-paramiko noarch 1.16.1-2.el7 epel 258 k
 virtualbox-iso: python2-pyasn1 noarch 0.1.9-7.el7 ol7_latest 99 k
 virtualbox-iso: sshpass x86_64 1.06-1.el7 epel 21 k
 virtualbox-iso:
 virtualbox-iso: Transaction Summary
 virtualbox-iso: ================================================================================
 virtualbox-iso: Install 1 Package (+18 Dependent packages)
 virtualbox-iso:
 virtualbox-iso: Total download size: 9.7 M
 virtualbox-iso: Installed size: 44 M
 virtualbox-iso: Downloading packages:
 virtualbox-iso: Public key for PyYAML-3.10-11.el7.x86_64.rpm is not installed
 virtualbox-iso: warning: /var/cache/yum/x86_64/7Server/ol7_latest/packages/PyYAML-3.10-11.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
 virtualbox-iso: Public key for ansible-2.3.1.0-1.el7.noarch.rpm is not installed
 virtualbox-iso: warning: /var/cache/yum/x86_64/7Server/epel/packages/ansible-2.3.1.0-1.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
 virtualbox-iso: --------------------------------------------------------------------------------
 virtualbox-iso: Total 1.5 MB/s | 9.7 MB 00:06
 virtualbox-iso: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 virtualbox-iso: Importing GPG key 0x352C64E5:
 virtualbox-iso: Userid : "Fedora EPEL (7) <epel@fedoraproject.org>"
 virtualbox-iso: Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 virtualbox-iso: Package : epel-release-7-10.noarch (installed)
 virtualbox-iso: From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 virtualbox-iso: Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
 virtualbox-iso: Importing GPG key 0xEC551F03:
 virtualbox-iso: Userid : "Oracle OSS group (Open Source Software group) <build@oss.oracle.com>"
 virtualbox-iso: Fingerprint: 4214 4123 fecf c55b 9086 313d 72f9 7b74 ec55 1f03
 virtualbox-iso: Package : 7:oraclelinux-release-7.4-1.0.4.el7.x86_64 (@anaconda/7.4)
 virtualbox-iso: From : /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
 virtualbox-iso: Running transaction check
 virtualbox-iso: Running transaction test
 virtualbox-iso: Transaction test succeeded
 virtualbox-iso: Running transaction
 virtualbox-iso: Installing : python-six-1.9.0-2.el7.noarch 1/19
 virtualbox-iso: Installing : python2-ecdsa-0.13-4.el7.noarch 2/19
 virtualbox-iso: Installing : sshpass-1.06-1.el7.x86_64 3/19
 virtualbox-iso: Installing : python-babel-0.9.6-8.el7.noarch 4/19
 virtualbox-iso: Installing : libtommath-0.42.0-5.el7.x86_64 5/19
 virtualbox-iso: Installing : libtomcrypt-1.17-25.el7.x86_64 6/19
 virtualbox-iso: Installing : python2-crypto-2.6.1-13.el7.x86_64 7/19
 virtualbox-iso: Installing : python2-paramiko-1.16.1-2.el7.noarch 8/19
 virtualbox-iso: Installing : python-backports-1.0-8.el7.x86_64 9/19
 virtualbox-iso: Installing : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 10/19
 virtualbox-iso: Installing : python-setuptools-0.9.8-7.el7.noarch 11/19
 virtualbox-iso: Installing : python2-pyasn1-0.1.9-7.el7.noarch 12/19
 virtualbox-iso: Installing : python-keyczar-0.71c-2.el7.noarch 13/19
 virtualbox-iso: Installing : python-httplib2-0.7.7-3.el7.noarch 14/19
 virtualbox-iso: Installing : python-markupsafe-0.11-10.el7.x86_64 15/19
 virtualbox-iso: Installing : python-jinja2-2.7.2-2.el7.noarch 16/19
 virtualbox-iso: Installing : libyaml-0.1.4-11.el7_0.x86_64 17/19
 virtualbox-iso: Installing : PyYAML-3.10-11.el7.x86_64 18/19
 virtualbox-iso: Installing : ansible-2.3.1.0-1.el7.noarch 19/19
 virtualbox-iso: Verifying : python-keyczar-0.71c-2.el7.noarch 1/19
 virtualbox-iso: Verifying : libyaml-0.1.4-11.el7_0.x86_64 2/19
 virtualbox-iso: Verifying : python-jinja2-2.7.2-2.el7.noarch 3/19
 virtualbox-iso: Verifying : libtomcrypt-1.17-25.el7.x86_64 4/19
 virtualbox-iso: Verifying : python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch 5/19
 virtualbox-iso: Verifying : python-markupsafe-0.11-10.el7.x86_64 6/19
 virtualbox-iso: Verifying : python-httplib2-0.7.7-3.el7.noarch 7/19
 virtualbox-iso: Verifying : python2-ecdsa-0.13-4.el7.noarch 8/19
 virtualbox-iso: Verifying : python2-pyasn1-0.1.9-7.el7.noarch 9/19
 virtualbox-iso: Verifying : python-backports-1.0-8.el7.x86_64 10/19
 virtualbox-iso: Verifying : python2-paramiko-1.16.1-2.el7.noarch 11/19
 virtualbox-iso: Verifying : ansible-2.3.1.0-1.el7.noarch 12/19
 virtualbox-iso: Verifying : libtommath-0.42.0-5.el7.x86_64 13/19
 virtualbox-iso: Verifying : PyYAML-3.10-11.el7.x86_64 14/19
 virtualbox-iso: Verifying : python-babel-0.9.6-8.el7.noarch 15/19
 virtualbox-iso: Verifying : python-six-1.9.0-2.el7.noarch 16/19
 virtualbox-iso: Verifying : python-setuptools-0.9.8-7.el7.noarch 17/19
 virtualbox-iso: Verifying : sshpass-1.06-1.el7.x86_64 18/19
 virtualbox-iso: Verifying : python2-crypto-2.6.1-13.el7.x86_64 19/19
 virtualbox-iso:
 virtualbox-iso: Installed:
 virtualbox-iso: ansible.noarch 0:2.3.1.0-1.el7
 virtualbox-iso:
 virtualbox-iso: Dependency Installed:
 virtualbox-iso: PyYAML.x86_64 0:3.10-11.el7
 virtualbox-iso: libtomcrypt.x86_64 0:1.17-25.el7
 virtualbox-iso: libtommath.x86_64 0:0.42.0-5.el7
 virtualbox-iso: libyaml.x86_64 0:0.1.4-11.el7_0
 virtualbox-iso: python-babel.noarch 0:0.9.6-8.el7
 virtualbox-iso: python-backports.x86_64 0:1.0-8.el7
 virtualbox-iso: python-backports-ssl_match_hostname.noarch 0:3.4.0.2-4.el7
 virtualbox-iso: python-httplib2.noarch 0:0.7.7-3.el7
 virtualbox-iso: python-jinja2.noarch 0:2.7.2-2.el7
 virtualbox-iso: python-keyczar.noarch 0:0.71c-2.el7
 virtualbox-iso: python-markupsafe.x86_64 0:0.11-10.el7
 virtualbox-iso: python-setuptools.noarch 0:0.9.8-7.el7
 virtualbox-iso: python-six.noarch 0:1.9.0-2.el7
 virtualbox-iso: python2-crypto.x86_64 0:2.6.1-13.el7
 virtualbox-iso: python2-ecdsa.noarch 0:0.13-4.el7
 virtualbox-iso: python2-paramiko.noarch 0:1.16.1-2.el7
 virtualbox-iso: python2-pyasn1.noarch 0:0.1.9-7.el7
 virtualbox-iso: sshpass.x86_64 0:1.06-1.el7
 virtualbox-iso:
 virtualbox-iso: Complete!
 virtualbox-iso: mount: /dev/loop0 is write-protected, mounting read-only
 virtualbox-iso: Verifying archive integrity... All good.
 virtualbox-iso: Uncompressing VirtualBox 5.1.26 Guest Additions for Linux...........
 virtualbox-iso: VirtualBox Guest Additions installer
 virtualbox-iso: Copying additional installer modules ...
 virtualbox-iso: Installing additional modules ...
 virtualbox-iso: vboxadd.sh: Starting the VirtualBox Guest Additions.
 virtualbox-iso:
 virtualbox-iso: Could not find the X.Org or XFree86 Window System, skipping.
 virtualbox-iso: dd: error writing ‘/root/tempfile’: No space left on device
 virtualbox-iso: 44824+0 records in
 virtualbox-iso: 44823+0 records out
 virtualbox-iso: 47000690688 bytes (47 GB) copied, 75.5318 s, 622 MB/s
==> virtualbox-iso: Gracefully halting virtual machine...
==> virtualbox-iso: Preparing to export machine...
 virtualbox-iso: Deleting forwarded port mapping for SSH (host port 3839)
==> virtualbox-iso: Exporting virtual machine...
 virtualbox-iso: Executing: export packer-ol74 --output output-ol74/packer-ol74.ovf
==> virtualbox-iso: Unregistering and deleting virtual machine...
==> virtualbox-iso: Running post-processor: vagrant
==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider
 virtualbox-iso (vagrant): Copying from artifact: output-ol74/packer-ol74-disk001.vmdk
 virtualbox-iso (vagrant): Copying from artifact: output-ol74/packer-ol74.ovf
 virtualbox-iso (vagrant): Renaming the OVF to box.ovf...
 virtualbox-iso (vagrant): Compressing: Vagrantfile
 virtualbox-iso (vagrant): Compressing: box.ovf
 virtualbox-iso (vagrant): Compressing: metadata.json
 virtualbox-iso (vagrant): Compressing: packer-ol74-disk001.vmdk
Build 'virtualbox-iso' finished.

==> Builds finished. The artifacts of successful builds are:
--> virtualbox-iso: 'virtualbox' provider box: ol74.box

 

After the box is created I usually add it to Vagrant as a local box, just to see that it works as it is supposed to.

vagrant box add ol74.box --name ol74

Once I’ve verified that everything is fine I remove the local box:

vagrant box remove ol74

And finally I upload it to Vagrant Cloud, and once it is released it is available as oravirt/ol74 in Vagrant.

 

 

 

 

Advertisements

4 thoughts on “Using packer to build a Vagrant box

  1. Pingback: Oracle Linux Vagrant boxes | oravirt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s