From 21df937172e917359ca43e9c9f4bd8697d4fa56b Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Fri, 2 Dec 2016 17:52:38 -0700 Subject: [PATCH] Add final changes for working OVN learning environment Add README.md with instructions on how to use the environment. Add final changes to the Vagrantfile and Ansible provisioning script. Add Jinja2 template for final setup script. Signed-off-by: Scott S. Lowe --- ovn/README.md | 28 +++++++++++++++++++--------- ovn/Vagrantfile | 5 +++++ ovn/provision.yml | 31 +++++++++++++++++++++++++++---- ovn/setup.sh.j2 | 14 ++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 ovn/setup.sh.j2 diff --git a/ovn/README.md b/ovn/README.md index 7afe86d..7085313 100644 --- a/ovn/README.md +++ b/ovn/README.md @@ -1,25 +1,35 @@ -# Generic Debian 8.0 ("Jessie") VM +# Open Virtual Network (OVN) -These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up a generic Debian 8.0 ("Jessie") 64-bit VM. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin. - -**NOTE:** There's really nothing special here; I created these files because I often had a need to quickly and easily spin up a generic Debian VM for some purpose (building a package or testing a command). I'm including them here just for the sake of completeness. +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up an environment to test Open Virtual Network (OVN), a part of the Open vSwitch project. ## Contents +* **ansible.cfg**: This is an Ansible configuration file that instructs Ansible to use the "vagrant" remote user, and to use Vagrant's built-in Ansible inventory. + +* **machines.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. + +* **provision.yml**: This Ansible playbook installs the OVS/OVN components on each Vagrant machine. It's called automatically by Vagrant. + * **README.md**: This file you're currently reading. -* **servers.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. +* **setup.sh.j2**: This Jinja2 template is used by Ansible to build a customized OVS/OVN configuration script for each Vagrant machine. The shell script created by this template is placed by Ansible in `/home/vagrant/setup.sh`. * **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. ## Instructions -These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. +These instructions assume you've already installed Vagrant, your back-end virtualization provider (such as VMware Fusion or VirtualBox), and any necessary plugins (such as the Vagrant VMware plugin). Please refer to the documentation for those products for more information on installation or configuration. -1. Use `vagrant box add` to add a 64-bit Debian 8.0 ("Jessie") base box to be used by this `Vagrantfile`. You'll need to specify a box that provides support for the `vmware_desktop` provider (it should work with either VMware Workstation or VMware Fusion). +1. Use `vagrant box add` to add an Ubuntu 16.04 box to your system. The "bento/ubuntu-16.04" box is very good for both VirtualBox and VMware Fusion/Workstation. (Note that the "ubuntu/xenial64" box for VirtualBox is currently broken under Vagrant.) -2. Edit the `servers.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" line of this file. +2. Edit the `machines.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" sections of this file. Specify the name of a VMware-formatted box on the "vmw:" line; place the name of a VirtualBox-formatted box on the "vb:" line. -3. Run `vagrant up`, and when the VM is up use `vagrant ssh` to access the generic Debian VM. +3. Run `vagrant up` to have Vagrant instantiate the three machines configured by default in this environment, and provision them using Ansible. (Note you'll need Ansible installed locally on the system where you're running `vagrant up`.) + +4. Use `vagrant ssh ovn-01` to log into the first system. Run `sudo ./setup.sh` to perform final configuration steps for OVS/OVN. + +5. Repeat step #4 with `ovn-02` and `ovn-03`. + +You now have a three-node system running OVN. The OVN central components are running on "ovn-01". Enjoy! diff --git a/ovn/Vagrantfile b/ovn/Vagrantfile index ed0d192..3f9888a 100644 --- a/ovn/Vagrantfile +++ b/ovn/Vagrantfile @@ -66,4 +66,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end # srv.vm.provider 'virtualbox' end # config.vm.define end # machines.each + + # Configure the machines with Ansible + config.vm.provision 'ansible' do |ansible| + ansible.playbook = 'provision.yml' + end # config.vm.provision end # Vagrant.configure diff --git a/ovn/provision.yml b/ovn/provision.yml index 521d3bd..7fc476e 100644 --- a/ovn/provision.yml +++ b/ovn/provision.yml @@ -4,19 +4,42 @@ remote_user: "vagrant" tasks: + - name: "Install Ubuntu Cloud Keyring package" + apt: + state: "present" + update_cache: "yes" + name: "ubuntu-cloud-keyring" + - name: "Add Ubuntu Cloud Archive repository" apt_repository: repo: "{{ item }}" state: "present" + update_cache: "yes" with_items: - - "deb http://cloud.archive.ubuntu.com/ubuntu newton main" + - "deb http://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton main" - name: "Install OVS/OVN 2.6.0" apt: state: "present" - update_cache: "yes" + update_cache: "no" name: "{{ item }}" with_items: - - "openvswitch-switch" + - "ovn-common" + - "ovn-host" - "openvswitch-common" - - "ovn-controller" + - "openvswitch-switch" + + - name: "Install central OVN components" + apt: + state: "present" + update_cache: "no" + name: "ovn-central" + when: ansible_hostname == "ovn-01" + + - name: "Install configuration script" + template: + src: "setup.sh.j2" + dest: "/home/vagrant/setup.sh" + owner: "vagrant" + group: "vagrant" + mode: "0755" diff --git a/ovn/setup.sh.j2 b/ovn/setup.sh.j2 new file mode 100644 index 0000000..6ad54ce --- /dev/null +++ b/ovn/setup.sh.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +# Stop the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl stop_controller + +# Configure OVS +sudo ovs-vsctl set Open_vSwitch . \ + external_ids:ovn-remote="tcp:192.168.100.101:6642" \ + external_ids:ovn-nb="tcp:192.168.100.101:6641" \ + external_ids:ovn-encap-ip={{ ansible_enp0s8.ipv4.address }} \ + external_ids:ovn-encap-type="geneve" + +# Start the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl start_controller