# Vim tmp files
.*sw?
-# Packer output dirs
+# Packer output
output-virtualbox-iso/
packer_cache/
+*.box
+Vagrantfile
OpenDaylight's current use-case for Packer is to build an ODL Vagrant base box, provisioned using upstream deployment/config tools. Reusing the logic of our configuration management tools nicely standardizes our deployment story, enabling good code reuse and separation of responsibilities. Providing an upstream Vagrant base box prevents all ODL consumers from duplicating ODL download, install and configuration logic, data transfer and computation in every Vagrantfile we create.
-## Building ODL Images
+We currently only support CentOS 7, output as a VirtualBox machine image, not packaged into a Vagrant box. Additional development is ongoing.
+
+## Building an ODL Vagrant Base Box
-After [installing Packer][2], build our ODL image with:
+After [installing Packer][2], build our ODL Vagrant base box with:
```
[~/integration/packaging/packer]$ packer build centos.json
```
-We currently only support CentOS 7, output as a VirtualBox machine image, not packaged into a Vagrant box. Additional development is ongoing.
+This will download and verify a fresh CentOS 7.1 Minimal ISO, use a Kickstart template to automate a minimal install against a VirtualBox host, run a post-install shell provisioner to configure the VM for use as a Vagrant base box and finally export, compress and package it as a Vagrant base box.
+
+```
+<snip>
+Build 'virtualbox-iso' finished.
+
+==> Builds finished. The artifacts of successful builds are:
+--> virtualbox-iso: 'virtualbox' provider box: opendaylight-centos-7.1.box
+[~/integration/packaging/packer]$ ls -lh opendaylight-centos-7.1.box
+-rw-rw-r--. 1 daniel daniel 532M Jun 5 00:32 opendaylight-centos-7.1.box
+```
+
+Import the local box into Vagrant with:
+
+```
+[~/integration/packaging/packer]$ vagrant box add --name "opendaylight" opendaylight-centos-7.1.box --force
+==> box: Adding box 'opendaylight' (v0) for provider:
+ box: Downloading: file:///home/daniel/integration/packaging/packer/opendaylight-centos-7.1.box
+==> box: Successfully added box 'opendaylight' (v0) for 'virtualbox'!
+```
+
+To connect to your new box, you'll need a trivial Vagrantfile:
+
+```
+[~/integration/packaging/packer]$ vagrant init -m opendaylight
+A `Vagrantfile` has been placed in this directory.<snip>
+[~/integration/packaging/packer]$ cat Vagrantfile
+Vagrant.configure(2) do |config|
+ config.vm.box = "opendaylight"
+end
+[~/integration/packaging/packer]$ vagrant ssh
+<snip>
+```
+
[1]: https://www.packer.io/
[2]: https://www.packer.io/intro/getting-started/setup.html
],
"iso_checksum": "7cf1ac8da13f54d6be41e3ccf228dc5bb35792f515642755ff4780d5714d4278",
"iso_checksum_type": "sha256",
+ "headless": "false",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
- "shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now",
+ "shutdown_command": "sudo shutdown -P now",
"http_directory": ".",
"boot_command": [
"<tab>text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/centos_kickstart.cfg<enter>"
+ ],
+ "vboxmanage": [
+ [
+ "modifyvm",
+ "{{ .Name }}",
+ "--memory",
+ "1024"
+ ],
+ [
+ "modifyvm",
+ "{{ .Name }}",
+ "--cpus",
+ "2"
+ ]
]
}
+ ],
+ "provisioners": [
+ {
+ "type": "shell",
+ "script": "config_vagrant.sh"
+ }
+ ],
+ "post-processors": [
+ {
+ "type": "vagrant",
+ "compression_level": "9",
+ "output": "opendaylight-centos-7.1.box"
+ }
]
}
%end
%post
- # Create vagrant user and group, give them correct permissions
- groupadd vagrant
- useradd vagrant -g vagrant -G wheel
- echo "vagrant" | passwd --stdin vagrant
- echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
+ # In the VM output, this is the "Running post-installation scripts" section.
+ # Unfortunately, it produces no output. The `yum update` step may give the
+ # appearance that the build is hung, as it's slow, uses little CPU and
+ # doesn't transfer much data during the package index building step.
# Update all packages
yum update -y
# Clear yum cache to save space
yum clean all
+
+ # Create vagrant user and group, give them correct permissions
+ # This needs to happen before Packer tries to SSH in and poweroff the VM,
+ # (at the end of the builder step), so it must be done here (in the
+ # builder step), not in an external script called by a Packer shell
+ # provisioner (after the builder step).
+ groupadd vagrant
+ useradd vagrant -g vagrant -G wheel
+ echo "vagrant" | passwd --stdin vagrant
+ echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
%end
--- /dev/null
+#!/usr/bin/env bash
+# Called by Packer to config a CentOS 7 machine for use as a Vagrant base box
+
+# Echo commands as they are run
+set -x
+
+# Install SSH key used by Vagrant for all interactions that connect to the box
+install -v -o vagrant -g vagrant -m 0700 -d /home/vagrant/.ssh
+curl -o /home/vagrant/.ssh/authorized_keys -kL "https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub"
+chmod 600 /home/vagrant/.ssh/authorized_keys
+chown -R vagrant:vagrant /home/vagrant/.ssh
+
+# Vagrant requires the ability to run sudo without a tty
+# Else, `vagrant up` will fail with: "sorry, you must have a tty to run sudo"
+sudo sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers