CORD-433 Add virtual fabric to CiaB

Change-Id: I8fbea8c85f309a4c226951e0cde96a9b7394d6eb
diff --git a/ansible/roles/leafswitch/tasks/bridge.yml b/ansible/roles/leafswitch/tasks/bridge.yml
new file mode 100644
index 0000000..1ee6a60
--- /dev/null
+++ b/ansible/roles/leafswitch/tasks/bridge.yml
@@ -0,0 +1,14 @@
+- name: Ensure brctl
+  apt:
+    name: bridge-utils
+    state: present
+
+- name: Ensure bridge
+  template:
+    src: templates/leafbr.cfg.j2
+    dest: /etc/network/interfaces.d/leafbr.cfg
+
+- name: Ensure bridge is up
+  command: ifup leafbr
+  tags:
+    - skip_ansible_lint # running a sub job
diff --git a/ansible/roles/leafswitch/tasks/fabric.yml b/ansible/roles/leafswitch/tasks/fabric.yml
new file mode 100644
index 0000000..98dc859
--- /dev/null
+++ b/ansible/roles/leafswitch/tasks/fabric.yml
@@ -0,0 +1,10 @@
+- name: Start ofdatapath
+  shell: pgrep ofdatapath || ofdatapath -i eth2,eth3,eth4,eth5 -d {{ ansible_eth1.macaddress | hwaddr('bare') }} --no-slicing -D punix:/var/run/cpqd.sock
+  tags:
+    - skip_ansible_lint # running a sub job
+
+# /etc/resolv.conf not set up correctly in switches, use controller IP addr instead
+- name: Start ofprotocol
+  shell: pgrep ofprotocol || ofprotocol -D --log-file=/var/log/ofprotocol.log unix:/var/run/cpqd.sock tcp:10.1.0.1:6653
+  tags:
+    - skip_ansible_lint # running a sub job
\ No newline at end of file
diff --git a/ansible/roles/leafswitch/tasks/main.yml b/ansible/roles/leafswitch/tasks/main.yml
new file mode 100644
index 0000000..5cc3a15
--- /dev/null
+++ b/ansible/roles/leafswitch/tasks/main.yml
@@ -0,0 +1,28 @@
+- name: Ensure interface config files
+  template:
+    src: templates/ethX.cfg.j2
+    dest: /etc/network/interfaces.d/{{ item }}.cfg
+  with_items:
+  - eth2
+  - eth3
+  - eth4
+  - eth5
+
+- name: Ensure interfaces are up
+  command: ifup {{ item }}
+  with_items:
+  - eth2
+  - eth3
+  - eth4
+  - eth5
+  tags:
+    - skip_ansible_lint # running a sub job
+
+- name: Ensure fabric configuration
+  include: fabric.yml
+  when: fabric
+
+- name: Ensure bridge configuration
+  include: bridge.yml
+  when: not fabric
+
diff --git a/ansible/roles/leafswitch/templates/ethX.cfg.j2 b/ansible/roles/leafswitch/templates/ethX.cfg.j2
new file mode 100644
index 0000000..424746b
--- /dev/null
+++ b/ansible/roles/leafswitch/templates/ethX.cfg.j2
@@ -0,0 +1,3 @@
+auto {{ item }}
+iface {{ item }} inet manual
+up ifconfig {{ item }} up
\ No newline at end of file
diff --git a/ansible/roles/leafswitch/templates/leafbr.cfg.j2 b/ansible/roles/leafswitch/templates/leafbr.cfg.j2
new file mode 100644
index 0000000..26a8caf
--- /dev/null
+++ b/ansible/roles/leafswitch/templates/leafbr.cfg.j2
@@ -0,0 +1,7 @@
+auto leafbr
+iface leafbr inet static
+    address {{ net_prefix }}.254
+    network {{ net_prefix }}.0
+    netmask 255.255.255.0
+    broadcast {{ net_prefix }}.255
+    bridge_ports eth2 eth3 eth4 eth5