Install ODL on Vagrant base box via Packer+Ansible
authorDaniel Farrell <dfarrell@redhat.com>
Tue, 9 Jun 2015 22:13:19 +0000 (18:13 -0400)
committerDaniel Farrell <dfarrell@redhat.com>
Tue, 9 Jun 2015 22:59:14 +0000 (18:59 -0400)
Use the ODL Ansible role to install OpenDaylight on
the ODL Vagrant base box via the ansible-local Packer
provisioner.

All documentation updates included.

Attempted to clean up the VM as much as possible, to
minimize the size of the resulting base box. I think
there are still optimizations to be made, but most of
the size is consumed by required things like ODL, Java,
Ansible (for ansible-local) and their dependences.

Change-Id: If11d2308036b44feb5bada86482b7e4413468735
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
packaging/packer/.gitignore
packaging/packer/README.markdown
packaging/packer/centos.json
packaging/packer/config_ansible.sh [new file with mode: 0644]
packaging/packer/config_virtualbox.sh
packaging/packer/install_odl.yml [new file with mode: 0644]
packaging/packer/requirements.yml [new file with mode: 0644]
packaging/packer/roles/.gitkeep [new file with mode: 0644]

index f90c3c5e99d30e323279199b5b8035da9a6dbfff..4e10e1812613b1ba4d24df6f3150553e0d831a27 100644 (file)
@@ -6,3 +6,5 @@ output-virtualbox-iso/
 packer_cache/
 *.box
 Vagrantfile
+roles/*
+!roles/.gitkeep
index 53361a2a081f33367002fdbe311a894a5f991680..e0c2613b93cdf7bee9f93189e131fc6cf356ecbf 100644 (file)
@@ -17,17 +17,36 @@ not packaged into a Vagrant box. Additional development is ongoing.
 
 ## Building an ODL Vagrant Base Box
 
-After [installing Packer][2], build our ODL Vagrant base box with:
+You'll need to [install Packer][2], of course.
+
+You'll also need to put a version of the [ODL Ansible role][4] in
+the directory expected by Packer:
+
+```
+[~/integration/packaging/packer]$ ansible-galaxy install -r requirements.yml --force
+- executing: git clone https://github.com/dfarrell07/ansible-opendaylight opendaylight
+- executing: git archive --prefix=opendaylight/ --output=/tmp/tmpKIgi21.tar HEAD
+- extracting opendaylight to roles/opendaylight
+- opendaylight was installed successfully
+```
+
+Note that the `ansible-galaxy` tool is provided by Ansible's package.
+
+You can now build our ODL Vagrant base box with:
 
 ```
 [~/integration/packaging/packer]$ packer build centos.json
 ```
 
-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.
+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 do VirtualBox, Vagrant
+  and Ansible-specific config.
+* Install OpenDaylight using its [Ansbile role][4].
+* Export, compress and package the VM as a Vagrant base box.
 
 ```
 <snip>
@@ -36,7 +55,7 @@ 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
+-rw-rw-r--. 1 daniel daniel 1.1G Jun  9 01:13 opendaylight-centos-7.1.box
 ```
 
 Import the local box into Vagrant with:
@@ -61,7 +80,15 @@ end
 <snip>
 ```
 
+OpenDaylight will already be installed and running:
+
+```
+[vagrant@localhost ~]$ sudo systemctl is-active opendaylight
+active
+```
+
 
 [1]: https://www.packer.io/
 [2]: https://www.packer.io/intro/getting-started/setup.html
 [3]: https://trello.com/c/OoS1aKaN/150-packaging-create-odl-vagrant-base-box
+[4]: https://github.com/dfarrell07/ansible-opendaylight
index b98c26a0deb1335246588f5a6f2a31f155004e88..c14de87bde1bf23f34ceaecd9a73b53fb1219ec6 100644 (file)
       "scripts":
         [
           "config_vagrant.sh",
-          "config_virtualbox.sh"
+          "config_virtualbox.sh",
+          "config_ansible.sh"
+        ]
+    },
+    {
+      "type": "ansible-local",
+      "playbook_file": "install_odl.yml",
+      "role_paths":
+        [
+          "roles/opendaylight"
         ]
     }
   ],
diff --git a/packaging/packer/config_ansible.sh b/packaging/packer/config_ansible.sh
new file mode 100644 (file)
index 0000000..ed33544
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# Install Ansible, as required for Packer's ansible-local provisioner.
+# Also installs EPEL (dependency).
+
+# Echo commands as they are run
+set -x
+
+# Install EPEL for access to Ansible repo
+# EPEL is okay to bake in, good minimization vs functionality trade-off
+sudo yum install -y epel-release
+
+# Install Ansible, required for Packer's ansible-local provisioner
+sudo yum install -y ansible
+
+# Clean up to save space
+sudo yum clean all -y
+sudo rm -rf /tmp/*
index 23a666f7725b5fc70e96f55f79729aef8f95e83d..b689819c48c378e8fc8b3a10b6ee935564569453 100644 (file)
@@ -15,3 +15,10 @@ sudo /mnt/VBoxLinuxAdditions.run
 # Clean up VirtualBox Guest Additions install media to save space
 sudo umount /mnt
 rm -rf /home/vagrant/VBoxGuestAdditions.iso
+rm -rf /usr/src/vboxguest*
+
+# Clean up utilities required by VB Guest Additions install to save space
+# Don't remove bzip2, it's only 87k. Removing gcc saves 37M, kernel-devel 32M.
+sudo yum remove -y gcc kernel-devel
+sudo yum clean all -y
+sudo rm -rf /tmp/*
diff --git a/packaging/packer/install_odl.yml b/packaging/packer/install_odl.yml
new file mode 100644 (file)
index 0000000..6f36f75
--- /dev/null
@@ -0,0 +1,5 @@
+---
+- hosts: localhost
+  sudo: yes
+  roles:
+    - opendaylight
diff --git a/packaging/packer/requirements.yml b/packaging/packer/requirements.yml
new file mode 100644 (file)
index 0000000..a128cf4
--- /dev/null
@@ -0,0 +1,7 @@
+# This is used to manage Ansible role dependences
+# http://docs.ansible.com/galaxy.html#installing-multiple-roles-from-a-file
+# Install with: `ansible-galaxy install -r requirements.yml`
+
+- name: opendaylight
+  src: https://github.com/dfarrell07/ansible-opendaylight
+  path: roles/
diff --git a/packaging/packer/roles/.gitkeep b/packaging/packer/roles/.gitkeep
new file mode 100644 (file)
index 0000000..e69de29