Refactor batch of issues with Packer/Vagrant box
authorDaniel Farrell <dfarrell@redhat.com>
Thu, 11 Jun 2015 06:09:36 +0000 (02:09 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 15 Jun 2015 11:14:32 +0000 (11:14 +0000)
Use Packer variables to track ODL's version.

Don't require install of ODL Ansible role by user before
Packer build, let Packer manage it (everything should be
tracked in VCS).

Use new CentOS version system and various other minor bug
fixes.

Using a Kludge of ODL's version scheme to hack ODL's
broken versioning scheme into semantic versioning. Vagrant
requires versions of the form X.Y.Z, so we couldn't do
the (ideal) 0.2.3-1 (the last part is *-<package version>).
Since ODL isn't really using the its major version, just
rotating left for now.

Update docs to reflect all changes.

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

index 4e10e1812613b1ba4d24df6f3150553e0d831a27..f90c3c5e99d30e323279199b5b8035da9a6dbfff 100644 (file)
@@ -6,5 +6,3 @@ output-virtualbox-iso/
 packer_cache/
 *.box
 Vagrantfile
-roles/*
-!roles/.gitkeep
index e0c2613b93cdf7bee9f93189e131fc6cf356ecbf..aebdaa657d081354338dd0d58600687d4b0f12f2 100644 (file)
@@ -13,34 +13,21 @@ ODL consumers from duplicating ODL download, install and configuration
 logic, data transfer and computation in every Vagrantfile we create.
 
 We currently only support CentOS 7, output as a VirtualBox machine image,
-not packaged into a Vagrant box. Additional development is ongoing.
+packaged into a Vagrant box. Additional development is ongoing.
 
 ## Building an ODL Vagrant Base Box
 
 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
+[~/integration/packaging/packer]$ packer build -var-file=packer_vars.json centos.json
 ```
 
 This will:
 
-* Download and verify a fresh CentOS 7.1 Minimal ISO.
+* Download and verify a fresh CentOS 1503 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
@@ -53,17 +40,17 @@ This will:
 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 1.1G Jun  9 01:13 opendaylight-centos-7.1.box
+--> virtualbox-iso: 'virtualbox' provider box: opendaylight-2.3.0-centos-1503.box
+[~/integration/packaging/packer]$ ls -lh opendaylight-2.3.0-centos-1503.box
+-rw-rw-r--. 1 daniel daniel 1.1G Jun  9 01:13 opendaylight-2.3.0-centos-1503.box
 ```
 
 Import the local box into Vagrant with:
 
 ```
-[~/integration/packaging/packer]$ vagrant box add --name "opendaylight" opendaylight-centos-7.1.box --force
+[~/integration/packaging/packer]$ vagrant box add --name "opendaylight" opendaylight-2.3.0-centos-1503.box --force
 ==> box: Adding box 'opendaylight' (v0) for provider:
-    box: Downloading: file:///home/daniel/integration/packaging/packer/opendaylight-centos-7.1.box
+    box: Downloading: file:///home/daniel/integration/packaging/packer/opendaylight-2.3.0-centos-1503.box
 ==> box: Successfully added box 'opendaylight' (v0) for 'virtualbox'!
 ```
 
@@ -87,8 +74,36 @@ OpenDaylight will already be installed and running:
 active
 ```
 
+## Pre-Built ODL Base Box
+
+While we'd eventually like to provide more official places to host ODL's
+base boxes, all of this is new and under active development. For now,
+you can consume the product of this Packer build configuration via
+Atlas (previously called be VagrantCloud), the de facto box hosting
+service at the moment. It's at [dfarrell07/opendaylight][5] for now, but
+of course we'd like to transfer it to an official OpenDaylight account
+eventually (a Help Desk ticket has been submitted).
+
+```
+[~/sandbox]$ vagrant init -m dfarrell07/opendaylight
+[~/sandbox]$ cat Vagrantfile
+Vagrant.configure(2) do |config|
+  config.vm.box = "dfarrell07/opendaylight"
+end
+[~/sandbox]$ vagrant up
+# Downloads box from Atlas
+# Boots box
+[~/sandbox]$ vagrant ssh
+[vagrant@localhost ~]$ sudo systemctl is-active opendaylight
+active
+[vagrant@localhost ~]$ /opt/opendaylight/bin/client
+<snip>
+opendaylight-user@root>
+```
+
 
 [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
+[5]: https://atlas.hashicorp.com/dfarrell07/boxes/opendaylight
index c14de87bde1bf23f34ceaecd9a73b53fb1219ec6..21f2fb14c4d97980cefa90c84b32a71829d74aad 100644 (file)
@@ -1,4 +1,7 @@
 {
+  "variables": {
+    "box_version": null
+  },
   "builders": [
     {
       "type": "virtualbox-iso",
     },
     {
       "type": "ansible-local",
-      "playbook_file": "install_odl.yml",
-      "role_paths":
-        [
-          "roles/opendaylight"
-        ]
+      "playbook_file": "install_odl.yml"
     }
   ],
   "post-processors": [
     {
       "type": "vagrant",
       "compression_level": "9",
-      "output": "opendaylight-centos-7.1.box"
+      "output": "opendaylight-{{ user `box_version` }}-centos-1503.box"
     }
   ]
 }
index ed335444609496ae65964e410944e8c70c08a515..527a2f0db8cda92e0eaaa00e444f776b023f63ba 100644 (file)
@@ -12,6 +12,20 @@ sudo yum install -y epel-release
 # Install Ansible, required for Packer's ansible-local provisioner
 sudo yum install -y ansible
 
+# Install the latest release of ODL's Ansible role from Ansible Galaxy
+# The `ansible-galaxy` tool was installed by Ansible's RPM
+# NB: This could also be done by locally installing ODL's role, then
+#     giving Packer it's local path via the role_paths argument to the
+#     ansible-local provisioner. However, that approach requires a
+#     step not managed by Packer (installing the role, which shouldn't
+#     be checked into VCS, locally). Not only does that break the
+#     model of being able to build directly from what's in VCS, it
+#     breaks pushes to do automated remote builds. We can/should only
+#     push what's version controlled, and we can't install the role
+#     pre-build manually on the remote host, so we have to let Packer
+#     own the ODL role install.
+sudo ansible-galaxy install dfarrell07.opendaylight
+
 # Clean up to save space
 sudo yum clean all -y
 sudo rm -rf /tmp/*
index b689819c48c378e8fc8b3a10b6ee935564569453..8f56953a66e9f79f0c1e470c782a56942f111916 100644 (file)
@@ -15,7 +15,7 @@ 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*
+sudo 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.
index 6f36f75b8f556e17110652223c3bfd31041628db..14a4600bcecd309d622c01b3f1e67ea0e8ba3458 100644 (file)
@@ -2,4 +2,4 @@
 - hosts: localhost
   sudo: yes
   roles:
-    - opendaylight
+    - dfarrell07.opendaylight
diff --git a/packaging/packer/packer_vars.json b/packaging/packer/packer_vars.json
new file mode 100644 (file)
index 0000000..2bfed16
--- /dev/null
@@ -0,0 +1,3 @@
+{
+  "box_version": "2.3.0"
+}
diff --git a/packaging/packer/requirements.yml b/packaging/packer/requirements.yml
deleted file mode 100644 (file)
index a128cf4..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# 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
deleted file mode 100644 (file)
index e69de29..0000000