Vagrant-Ansible scripts for tutorial vm
Change-Id: I0481fa9c7df897812a765973440b6b1b2bf669f8
diff --git a/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml b/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml
index 002509a..346e2f3 100644
--- a/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml
+++ b/tools/dev/vagrant/ansible/roles/brctl/tasks/main.yml
@@ -1,37 +1,54 @@
-- name: Bridge onosbr0 is present
+---
+#
+# Configures networking and Linux brdiges
+#
+- name: Creating ONOS bridge
become: yes
template:
src: templates/create_bridge.j2
- dest: /etc/network/if-pre-up.d/create_bridge_{{ networks.bridge_name }}
+ dest: "/etc/network/if-pre-up.d/create_bridge_{{ bridge.name }}"
owner: root
group: root
mode: 0755
-- name: eth1 is in onosbr0
+- name: Adding second NIC to ONOS bridge
become: yes
template:
src: templates/add_iface.j2
- dest: /etc/network/if-pre-up.d/add_iface_{{ interfaces.hostonly }}
+ dest: "/etc/network/if-pre-up.d/add_iface_{{ bridge.phy_interface }}"
owner: root
group: root
mode: 0755
-- name: Activate onos bridge
+- name: Activating ONOS bridge
become: yes
- command: /etc/network/if-pre-up.d/create_bridge_{{ networks.bridge_name }} report-changed
+ command: /etc/network/if-pre-up.d/create_bridge_{{ bridge.name }} report-changed
register: bridge_changed
changed_when: bridge_changed.stdout == 'true'
-- name: Activate eth1 in bridge
+- name: Adding physical interface to the bridge
become: yes
- command: /etc/network/if-pre-up.d/add_iface_{{ interfaces.hostonly }} report-changed
+ command: /etc/network/if-pre-up.d/add_iface_{{ bridge.phy_interface }} report-changed
register: bridge_iface_changed
changed_when: bridge_iface_changed == 'true'
-- name: Flush ip of eth1
+- name: Moving the IP and starting bridge automatically at startup
become: yes
- command: /sbin/ip addr flush {{ interfaces.hostonly }}
+ template:
+ src: templates/post_ifup.j2
+ dest: "/etc/network/if-up.d/bring_up_{{ bridge.name }}"
+ owner: root
+ group: root
+ mode: 0755
+
+- name: Removing IP from the second NIC
+ become: yes
+ command: "/sbin/ip addr flush {{ bridge.phy_interface }}"
-- name: bring onosbr0 up
+- name: Configuring the IP on the bridge
become: yes
- command: /sbin/ifconfig onosbr0 up
+ command: "/sbin/ifconfig {{ bridge.name }} inet {{ bridge.ip }}"
+
+- name: Bringing up ONOS bridge
+ become: yes
+ command: "/sbin/ifconfig {{ bridge.name }} up"
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2 b/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2
index f09bd50..b391252 100644
--- a/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2
+++ b/tools/dev/vagrant/ansible/roles/brctl/templates/add_iface.j2
@@ -6,12 +6,12 @@
fi
CHANGED='false'
-FOUND=$(brctl show | grep "^{{ interfaces.hostonly }}" | wc -l)
+FOUND=$(brctl show | grep "^{{ bridge.phy_interface }}" | wc -l)
if [ $FOUND -eq 0 ]; then
CHANGED='true'
- brctl addif {{ networks.bridge_name }} {{ interfaces.hostonly }}
+ brctl addif {{ bridge.name }} {{ bridge.phy_interface }}
fi
if [ $REPORT_CHANGED -ne 0 ]; then
echo -n $CHANGED
-fi
+fi
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2 b/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2
index 5f12261..c301d11 100644
--- a/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2
+++ b/tools/dev/vagrant/ansible/roles/brctl/templates/create_bridge.j2
@@ -6,12 +6,12 @@
fi
CHANGED='false'
-FOUND=$(brctl show | grep "^{{ networks.bridge_name }}" | wc -l)
+FOUND=$(brctl show | grep "^{{ bridge.name }}" | wc -l)
if [ $FOUND -eq 0 ]; then
CHANGED='true'
- brctl addbr {{ networks.bridge_name }}
+ brctl addbr {{ bridge.name }}
fi
if [ $REPORT_CHANGED -ne 0 ]; then
echo -n $CHANGED
-fi
+fi
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/brctl/templates/post_ifup.j2 b/tools/dev/vagrant/ansible/roles/brctl/templates/post_ifup.j2
new file mode 100644
index 0000000..4156a2e
--- /dev/null
+++ b/tools/dev/vagrant/ansible/roles/brctl/templates/post_ifup.j2
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+ip addr flush {{ bridge.phy_interface }}
+ifconfig {{ bridge.name }} inet {{ bridge.ip }}
+ifconfig {{ bridge.name }} up
\ No newline at end of file
diff --git a/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml b/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml
deleted file mode 100644
index 5c705ac..0000000
--- a/tools/dev/vagrant/ansible/roles/brctl/vars/main.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-interfaces:
- hostonly: "{{ hostonly_iface | default('eth1') }}"
-
-networks:
- # CHANGE:
- # 'bridge' name of the bridge to create that is used when connecting
- # the LXC containers
- bridge_name: "{{ bridge_name | default('onosbr0') }}"
- bridge: "{{ bridge_network | default('10.100.198.200/24') }}"