Last active
February 28, 2019 13:31
-
-
Save upa/53704e9e68aa4f2ede0fb67db07fa15b to your computer and use it in GitHub Desktop.
A Vagrantfile and Ansible playbooks for deploying a lagopus router and edge node using ansible-based provisioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ubuntu 18.04 does not have python2 by default | |
# but ansible still depends on python2 | |
- hosts: lagopus | |
become: yes | |
gather_facts: no | |
pre_tasks: | |
- name: install python2 | |
raw: sudo apt-get install -y python | |
# configure lagopus | |
- hosts: lagopus | |
vars: | |
GOPATH : /home/vagrant/go | |
VSWCONF: /home/vagrant/vsw.conf | |
environment: | |
GOPATH: "{{ GOPATH }}" | |
PATH: "{{ lookup('env', 'PATH') }}:{{ GOPATH }}/bin" | |
LD_LIBRARY_PATH: /usr/src/dpdk-stable-17.11.1/build/lib | |
tasks: | |
- include: setup.yml | |
- name: bind device to dpdk driver | |
become: yes | |
devbind: device={{ item }} driver=igb_uio | |
with_items: | |
- "0000:00:09.0" | |
- "0000:00:0a.0" | |
- name: spawn vsw | |
become: yes | |
spawn: | |
args: vsw -v -f {{ VSWCONF }} | |
pidfile: /tmp/vsw.pid | |
stderr: /tmp/vsw-stderr | |
stdout: /tmp/vsw-stdout | |
async: 10 | |
poll: 1 | |
- name: configure vsw | |
vswconfig: config={{ item }} | |
with_items: | |
- set interfaces interface if0 config mtu 1514 | |
- set interfaces interface if0 config driver dpdk | |
- set interfaces interface if0 config device 0000:00:09.0 | |
- set interfaces interface if0 config type ethernetCsmacd | |
- set interfaces interface if0 ethernet switched-vlan config interface-mode ACCESS | |
- set interfaces interface if0 ethernet switched-vlan config access-vlan 100 | |
- set interfaces interface if0 subinterfaces subinterface 0 config enabled true | |
- set interfaces interface if0 subinterfaces subinterface 0 vlan config vlan-id 100 | |
- set interfaces interface if0 config enabled true | |
- set interfaces interface if1 config mtu 1514 | |
- set interfaces interface if1 config driver dpdk | |
- set interfaces interface if1 config device 0000:00:0a.0 | |
- set interfaces interface if1 config type ethernetCsmacd | |
- set interfaces interface if1 ethernet switched-vlan config interface-mode ACCESS | |
- set interfaces interface if1 ethernet switched-vlan config access-vlan 100 | |
- set interfaces interface if1 subinterfaces subinterface 0 vlan config vlan-id 100 | |
- set interfaces interface if1 subinterfaces subinterface 0 config enabled true | |
- set interfaces interface if1 config enabled true | |
- set network-instances network-instance vsi1 config type L2VSI | |
- set network-instances network-instance vsi1 config enabled true | |
- set network-instances network-instance vsi1 vlans vlan 100 config status ACTIVE | |
- set network-instances network-instance vsi1 fdb config mac-learning true | |
- set network-instances network-instance vsi1 fdb config mac-aging-time 300 | |
- set network-instances network-instance vsi1 fdb config maximum-entries 3000 | |
- set network-instances network-instance vsi1 interfaces interface if0 subinterface 0 | |
- set network-instances network-instance vsi1 interfaces interface if1 subinterface 0 | |
- commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: node1 | |
become: yes | |
gather_facts: no | |
pre_tasks: | |
- name: install python2 | |
raw: sudo apt-get install -y python | |
- hosts: node1 | |
become: yes | |
vars: | |
NETNS: testns | |
tasks: | |
- name: setup networking | |
command: "{{ item }}" | |
with_items: | |
- ip netns add {{ NETNS }} | |
- ip link set dev eth3 netns {{ NETNS }} | |
- ip netns exec {{ NETNS }} ip link set dev eth3 up | |
- ip netns exec {{ NETNS }} ip addr add dev eth3 10.0.0.21/24 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# isntall required software | |
- name: install required packages | |
become: yes | |
apt: | |
name: [ "libnuma-dev", "libelf-dev", "autoconf", "golang", "go-dep" ] | |
- name: install dpdk | |
become: yes | |
dpdk_install: build_shared_lib=true jobs=6 | |
# install and spawn vsw and related software | |
- name: go get openconfigd | |
command: "{{ item }}" | |
with_items: | |
- go get github.com/coreswitch/openconfigd/openconfigd | |
- go get github.com/coreswitch/openconfigd/cli_command | |
- name: configure, make, make install cli | |
become: yes | |
command: "{{ item }}" | |
with_items: | |
- ./configure | |
- make | |
- make install | |
- cp ../bash_completion.d/cli /etc/bash_completion.d/ | |
args: | |
chdir: "{{ GOPATH }}/src/github.com/coreswitch/openconfigd/cli" | |
- name: create vsw src directroy | |
file: path={{ GOPATH }}/src/github.com/lagopus state=directory | |
- name: download vsw | |
git: | |
repo: https://github.com/lagopus/vsw.git | |
dest: "{{ GOPATH }}/src/github.com/lagopus/vsw" | |
- name: install vsw | |
command: "{{ item }}" | |
with_items: | |
- dep ensure | |
- go install | |
args: | |
chdir: "{{ GOPATH }}/src/github.com/lagopus/vsw" | |
- name: install lagopus-router | |
git: | |
repo: https://github.com/lagopus/lagopus-router.git | |
dest: "{{ GOPATH }}/src/github.com/lagopus/lagopus-router" | |
- name: put vsw.conf | |
copy: src=vsw.conf dest={{ VSWCONF }} | |
- name: set hugepages | |
become: yes | |
hugepages: nr_pages=1024 | |
- name: spawn openconfid | |
spawn: | |
args: openconfigd -y modules:modules/policy:modules/bgp:modules/interfaces:modules/local-routing:modules/vlan:modules/rib:modules/network-instance:modules/types lagopus-router.yang | |
cwd: "{{ GOPATH }}/src/github.com/lagopus/lagopus-router/yang" | |
pidfile: /tmp/openconfid.pid | |
stderr: /tmp/openconfigd-stderr | |
stdout: /tmp/openconfigd-stdout | |
async: 10 | |
poll: 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "generic/ubuntu1804" | |
config.vm.define :lagopus do |box| | |
box.vm.box = "generic/ubuntu1804" | |
box.vm.hostname = "lagopus" | |
box.vm.network :private_network, ip: "192.168.55.11" | |
box.vm.network :private_network, ip: "0.0.0.0", auto_config: false, virtualbox__intnet: "lago-edge-1" | |
box.vm.network :private_network, ip: "0.0.0.0", auto_config: false, virtualbox__intnet: "lago-edge-2" | |
box.vm.provider "virtualbox" do |vb| | |
vb.memory = "4096" | |
vb.cpus = "4" | |
vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"] | |
vb.customize ["modifyvm", :id, "--nicpromisc4", "allow-all"] | |
end | |
box.vm.provision "ansible" do |ansible| | |
ansible.playbook = "provisioning/lagopus.yml" | |
ansible.inventory_path = "provisioning/hosts" | |
ansible.limit = 'all' | |
end | |
end | |
config.vm.define :node1 do |box| | |
box.vm.box = "generic/ubuntu1804" | |
box.vm.hostname = "node1" | |
box.vm.network :private_network, ip: "192.168.55.12" | |
box.vm.network :private_network, ip: "10.0.0.20", virtualbox__intnet: "lago-edge-1" | |
box.vm.network :private_network, ip: "0.0.0.0", auto_config: false, virtualbox__intnet: "lago-edge-2" | |
box.vm.provider "virtualbox" do |vb| | |
vb.customize ["modifyvm", :id, "--nicpromisc2", "allow-all"] | |
vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"] | |
end | |
box.vm.provision "ansible" do |ansible| | |
ansible.playbook = "provisioning/node1.yml" | |
ansible.inventory_path = "provisioning/hosts" | |
ansible.limit = 'all' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment