mirror of
https://codeberg.org/scottslowe/learning-tools.git
synced 2026-03-11 09:04:37 +00:00
commit
439cf463ec
6 changed files with 201 additions and 0 deletions
35
ovn/README.md
Normal file
35
ovn/README.md
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# 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 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.
|
||||
|
||||
* **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 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 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 `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` 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!
|
||||
74
ovn/Vagrantfile
vendored
Normal file
74
ovn/Vagrantfile
vendored
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
# Specify minimum Vagrant version and Vagrant API version
|
||||
Vagrant.require_version '>= 1.6.0'
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
# Require 'yaml' module
|
||||
require 'yaml'
|
||||
|
||||
# Read YAML file with VM details (box, CPU, RAM, IP addresses)
|
||||
# Edit machines.yml to change VM configuration details
|
||||
machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml'))
|
||||
|
||||
# Create and configure the VMs
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
|
||||
# Always use Vagrant's default insecure key
|
||||
config.ssh.insert_key = false
|
||||
|
||||
# Iterate through entries in YAML file to create VMs
|
||||
machines.each do |machine|
|
||||
|
||||
# Configure the VMs per details in machines.yml
|
||||
config.vm.define machine['name'] do |srv|
|
||||
|
||||
# Don't check for box updates
|
||||
srv.vm.box_check_update = false
|
||||
|
||||
# Specify the hostname of the VM
|
||||
srv.vm.hostname = machine['name']
|
||||
|
||||
# Specify the Vagrant box to use (use VMware box by default)
|
||||
srv.vm.box = machine['box']['vmw']
|
||||
|
||||
# Configure default synced folder (disable by default)
|
||||
if machine['sync_disabled'] != nil
|
||||
srv.vm.synced_folder '.', '/vagrant', disabled: machine['sync_disabled']
|
||||
else
|
||||
srv.vm.synced_folder '.', '/vagrant', disabled: true
|
||||
end #if machine['sync_disabled']
|
||||
|
||||
# Iterate through networks as per settings in machines.yml
|
||||
machine['nics'].each do |net|
|
||||
if net['ip_addr'] == 'dhcp'
|
||||
srv.vm.network net['type'], type: net['ip_addr']
|
||||
else
|
||||
srv.vm.network net['type'], ip: net['ip_addr']
|
||||
end # if net['ip_addr']
|
||||
end # machine['nics'].each
|
||||
|
||||
# Configure CPU & RAM per settings in machines.yml (Fusion)
|
||||
srv.vm.provider 'vmware_fusion' do |vmw|
|
||||
vmw.vmx['memsize'] = machine['ram']
|
||||
vmw.vmx['numvcpus'] = machine['vcpu']
|
||||
if machine['nested'] == true
|
||||
vmw.vmx['vhv.enable'] = 'TRUE'
|
||||
end #if machine['nested']
|
||||
end # srv.vm.provider 'vmware_fusion'
|
||||
|
||||
# Configure CPU & RAM per settings in machines.yml (VirtualBox)
|
||||
srv.vm.provider 'virtualbox' do |vb, override|
|
||||
vb.memory = machine['ram']
|
||||
vb.cpus = machine['vcpu']
|
||||
override.vm.box = machine['box']['vb']
|
||||
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
|
||||
5
ovn/ansible.cfg
Normal file
5
ovn/ansible.cfg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[defaults]
|
||||
inventory = ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
|
||||
private_key_file = ~/.vagrant.d/insecure_private_key
|
||||
remote_user = vagrant
|
||||
host_key_checking = False
|
||||
28
ovn/machines.yml
Normal file
28
ovn/machines.yml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
- name: "ovn-01"
|
||||
box:
|
||||
vmw: "bento/ubuntu-16.04"
|
||||
vb: "bento/ubuntu-16.04"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.101"
|
||||
- name: "ovn-02"
|
||||
box:
|
||||
vmw: "bento/ubuntu-16.04"
|
||||
vb: "bento/ubuntu-16.04"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.102"
|
||||
- name: "ovn-03"
|
||||
box:
|
||||
vmw: "bento/ubuntu-16.04"
|
||||
vb: "bento/ubuntu-16.04"
|
||||
ram: "512"
|
||||
vcpu: "1"
|
||||
nics:
|
||||
- type: "private_network"
|
||||
ip_addr: "192.168.100.103"
|
||||
45
ovn/provision.yml
Normal file
45
ovn/provision.yml
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
- hosts: "all"
|
||||
become: "yes"
|
||||
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://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton main"
|
||||
|
||||
- name: "Install OVS/OVN 2.6.0"
|
||||
apt:
|
||||
state: "present"
|
||||
update_cache: "no"
|
||||
name: "{{ item }}"
|
||||
with_items:
|
||||
- "ovn-common"
|
||||
- "ovn-host"
|
||||
- "openvswitch-common"
|
||||
- "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"
|
||||
14
ovn/setup.sh.j2
Normal file
14
ovn/setup.sh.j2
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue