Install ODL on Vagrant base box via Packer+Ansible
[integration.git] / packaging / packer / README.markdown
1 # OpenDaylight Packer
2
3 [Packer][1] is a tool for automatically creating well-defined machine
4 images of various types and optionally post-processing them into
5 Vagrant base boxes, among other options.
6
7 OpenDaylight's current use-case for Packer is to build an ODL Vagrant
8 base box, provisioned using upstream deployment/config tools. Reusing
9 the logic of our configuration management tools nicely standardizes our
10 deployment story, enabling good code reuse and separation of
11 responsibilities. Providing an upstream Vagrant base box prevents all
12 ODL consumers from duplicating ODL download, install and configuration
13 logic, data transfer and computation in every Vagrantfile we create.
14
15 We currently only support CentOS 7, output as a VirtualBox machine image,
16 not packaged into a Vagrant box. Additional development is ongoing.
17
18 ## Building an ODL Vagrant Base Box
19
20 You'll need to [install Packer][2], of course.
21
22 You'll also need to put a version of the [ODL Ansible role][4] in
23 the directory expected by Packer:
24
25 ```
26 [~/integration/packaging/packer]$ ansible-galaxy install -r requirements.yml --force
27 - executing: git clone https://github.com/dfarrell07/ansible-opendaylight opendaylight
28 - executing: git archive --prefix=opendaylight/ --output=/tmp/tmpKIgi21.tar HEAD
29 - extracting opendaylight to roles/opendaylight
30 - opendaylight was installed successfully
31 ```
32
33 Note that the `ansible-galaxy` tool is provided by Ansible's package.
34
35 You can now build our ODL Vagrant base box with:
36
37 ```
38 [~/integration/packaging/packer]$ packer build centos.json
39 ```
40
41 This will:
42
43 * Download and verify a fresh CentOS 7.1 Minimal ISO.
44 * Use a Kickstart template to automate a minimal install against
45   a VirtualBox host.
46 * Run a post-install shell provisioner to do VirtualBox, Vagrant
47   and Ansible-specific config.
48 * Install OpenDaylight using its [Ansbile role][4].
49 * Export, compress and package the VM as a Vagrant base box.
50
51 ```
52 <snip>
53 Build 'virtualbox-iso' finished.
54
55 ==> Builds finished. The artifacts of successful builds are:
56 --> virtualbox-iso: 'virtualbox' provider box: opendaylight-centos-7.1.box
57 [~/integration/packaging/packer]$ ls -lh opendaylight-centos-7.1.box
58 -rw-rw-r--. 1 daniel daniel 1.1G Jun  9 01:13 opendaylight-centos-7.1.box
59 ```
60
61 Import the local box into Vagrant with:
62
63 ```
64 [~/integration/packaging/packer]$ vagrant box add --name "opendaylight" opendaylight-centos-7.1.box --force
65 ==> box: Adding box 'opendaylight' (v0) for provider:
66     box: Downloading: file:///home/daniel/integration/packaging/packer/opendaylight-centos-7.1.box
67 ==> box: Successfully added box 'opendaylight' (v0) for 'virtualbox'!
68 ```
69
70 To connect to your new box, you'll need a trivial Vagrantfile:
71
72 ```
73 [~/integration/packaging/packer]$ vagrant init -m opendaylight
74 A `Vagrantfile` has been placed in this directory.<snip>
75 [~/integration/packaging/packer]$ cat Vagrantfile
76 Vagrant.configure(2) do |config|
77   config.vm.box = "opendaylight"
78 end
79 [~/integration/packaging/packer]$ vagrant ssh
80 <snip>
81 ```
82
83 OpenDaylight will already be installed and running:
84
85 ```
86 [vagrant@localhost ~]$ sudo systemctl is-active opendaylight
87 active
88 ```
89
90
91 [1]: https://www.packer.io/
92 [2]: https://www.packer.io/intro/getting-started/setup.html
93 [3]: https://trello.com/c/OoS1aKaN/150-packaging-create-odl-vagrant-base-box
94 [4]: https://github.com/dfarrell07/ansible-opendaylight