Merge branch 'master' of http://gerrit.opencord.org/maas
diff --git a/build.gradle b/build.gradle
index 1ed7930..3ab4704 100644
--- a/build.gradle
+++ b/build.gradle
@@ -227,6 +227,57 @@
   }
 }
 
+task prime (type: Exec) {
+    println "Using deployment config: $deployConfig"
+    File configFile = new File(deployConfig)
+    def yaml = new Yaml()
+    def config = yaml.load(configFile.newReader())
+
+    executable = "ansible-playbook"
+    args = ["-i", config.seedServer.ip + ',']
+
+    if ( config.seedServer.user != null && config.seedServer.user != "" ) {
+        args = args << "--user=$config.seedServer.user"
+    }
+
+    def extraVars = []
+    if (config.seedServer) {
+        extraVars = extraVars.p(config.seedServer.extraVars)
+            .p(config.seedServer.password, "ansible_ssh_pass")
+            .p(config.seedServer.sudoPassword, "ansible_sudo_pass")
+            .p(config.seedServer.fabric_ip, "fabric_ip")
+            .p(config.seedServer.management_ip, "management_ip")
+            .p(config.seedServer.management_network, "management_network")
+            .p(config.seedServer.management_iface, "management_iface")
+            .p(config.seedServer.external_ip, "external_ip")
+            .p(config.seedServer.external_network, "external_network")
+            .p(config.seedServer.external_iface, "external_iface")
+            .p(config.seedServer.fabric_ip, "fabric_ip")
+            .p(config.seedServer.fabric_network, "fabric_network")
+            .p(config.seedServer.fabric_iface, "fabric_iface")
+            .p(config.seedServer.domain, "domain")
+    }
+
+    if (vboxUser != "") {
+        extraVars = extraVars.p(vboxUser, "power_helper_user")
+    }
+
+    if (config.otherServers) {
+        extraVars = extraVars.p(config.otherServers.location, "prov_location")
+        .p(config.otherServers.rolesPath, "prov_role_path")
+        .p(config.otherServers.role, "prov_role")
+    }
+
+    if (config.docker) {
+        extraVars = extraVars.p(config.docker.registry, "docker_registry")
+            .p(config.docker.imageVersion, "docker_image_version")
+    }
+
+    def skipTags = [].p(config.seedServer.skipTags)
+
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "prime-node.yml"
+}
+
 task deploy (type: Exec) {
     println "Using deployment config: $deployConfig"
     File configFile = new File(deployConfig)
diff --git a/prime-node.yml b/prime-node.yml
new file mode 100644
index 0000000..79553a5
--- /dev/null
+++ b/prime-node.yml
@@ -0,0 +1,4 @@
+- hosts: all
+  serial: 1
+  roles:
+    - registry
diff --git a/roles/fabric-switch/files/connect b/roles/fabric-switch/files/connect
index a114178..8fa37e8 100755
--- a/roles/fabric-switch/files/connect
+++ b/roles/fabric-switch/files/connect
@@ -10,8 +10,15 @@
   shift
 done
 
+IP=$(ping -c 1 {{ controller_ip }} 2>/dev/null | grep PING | awk '{print $3}' | sed -e 's/[\(\)]//g')
+while [ "$IP x" == " x" ]; do
+  echo "Waiting for controller to resolve ({{ controller_ip }}) ... sleeping 5s and will try again ..."
+  sleep 5
+  IP=$(ping -c 1 {{ controller_ip }} 2>/dev/null | grep PING | awk '{print $3}' | sed -e 's/[\(\)]//g')
+done
+
 if [ $BG -eq 1 ]; then
-  nohup brcm-indigo-ofdpa-ofagent --dpid={{ switch_id }} --controller={{ controller_ip }} 2>&1 > connect.log &
+  nohup brcm-indigo-ofdpa-ofagent --dpid={{ switch_id }} --controller=$IP 2>&1 > connect.log &
 else
-  brcm-indigo-ofdpa-ofagent --dpid={{ switch_id }} --controller={{ controller_ip }}
+  brcm-indigo-ofdpa-ofagent --dpid={{ switch_id }} --controller=$IP
 fi
diff --git a/roles/fabric-switch/tasks/main.yml b/roles/fabric-switch/tasks/main.yml
index 326219a..6bbb9df 100644
--- a/roles/fabric-switch/tasks/main.yml
+++ b/roles/fabric-switch/tasks/main.yml
@@ -1,20 +1,28 @@
 ---
-- name: Verify controller_ip Set
-  fail: msg="Please set variable 'controller_ip'. This can be set via a variable file or via the command line using the '--extra-vars' option."
-  when: controller_ip is not defined
+- name: Generate DPID
+  shell: ifconfig ma1 | grep HWaddr | awk '{ print "0x0000"$5 }' | sed s/://g
+  register: dpid
+  changed_when: false
 
-- name: Verify switch_id Set
-  fail: msg="Please set variable 'switch_id'. This can be set via a host specific variable file or via the command line using the '--extra-vars' option."
-  when: switch_id is not defined
+- name: Ensure ofdpa Config
+  set_fact:
+    switch_id: "{{ dpid.stdout }}"
+    controller_ip: "onos-fabric"
+
+- name: Verify Openflow Agent
+  shell: which ofdpa | wc -w
+  register: ofdpa_exists
+  changed_when: false
 
 - name: Openflow Agent Version
   shell: ofdpa --version
   register: ofdpa_version
   changed_when: false
+  when: ofdpa_exists.stdout != "0"
 
 - name: Version I.12.1.1+1.1 Openflow Agent
   include: ofdpa.yml
-  when: ofdpa_version.stdout.find('version I.12.1.1+1.1') == -1
+  when: ofdpa_exists.stdout == "0" or ofdpa_version.stdout.find('version I.12.1.1+1.1') == -1
 
 - name: Utilities Scripts
   template:
diff --git a/roles/maas/tasks/main.yml b/roles/maas/tasks/main.yml
index 7da2082..2f3490d 100644
--- a/roles/maas/tasks/main.yml
+++ b/roles/maas/tasks/main.yml
@@ -63,6 +63,9 @@
   apt:
     name: maas
     state: latest
+    force: yes
+    update_cache: yes
+    allow_unauthenticated: yes
 
 - name: MAAS Configuration Directory
   become: yes
@@ -215,7 +218,7 @@
 
 - name: Configure MAAS
   become: yes
-  command: docker run opencord/cord-maas-bootstrap:latest --apikey='{{apikey.stdout}}' --sshkey='{{maas.user_sshkey}}' --url='http://{{mgmt_ip_address.stdout}}/MAAS/api/1.0' --network='{{networks.management}}' --interface='{{interfaces.management}}' --zone='administrative' --cluster='Cluster master' --domain='{{maas.domain}}' --bridge='{{networks.bridge_name}}' --bridge-subnet='{{networks.bridge}}'
+  command: docker run docker-registry:5000/cord-maas-bootstrap:{{ docker.image_version }} --apikey='{{apikey.stdout}}' --sshkey='{{maas.user_sshkey}}' --url='http://{{mgmt_ip_address.stdout}}/MAAS/api/1.0' --network='{{networks.management}}' --interface='{{interfaces.management}}' --zone='administrative' --cluster='Cluster master' --domain='{{maas.domain}}' --bridge='{{networks.bridge_name}}' --bridge-subnet='{{networks.bridge}}'
   register: maas_config_result
   changed_when: maas_config_result.stdout.find("CHANGED") != -1
   failed_when: "maas_config_result.rc != 0 or 'ERROR' in maas_config_result.stdout"
diff --git a/roles/maas/templates/automation-compose.yml.j2 b/roles/maas/templates/automation-compose.yml.j2
index 0154f84..5dc952b 100644
--- a/roles/maas/templates/automation-compose.yml.j2
+++ b/roles/maas/templates/automation-compose.yml.j2
@@ -1,5 +1,5 @@
 allocator:
-  image: "{{ docker.registry }}/cord-ip-allocator:{{ docker.image_version }}"
+  image: "docker-registry:5000/cord-ip-allocator:{{ docker.image_version }}"
   container_name: allocator
   labels:
     - "lab.solution=CORD"
@@ -14,7 +14,7 @@
   restart: unless-stopped
 
 provisioner:
-  image: "{{ docker.registry }}/cord-provisioner:{{ docker.image_version }}"
+  image: "docker-registry:5000/cord-provisioner:{{ docker.image_version }}"
   container_name: provisioner
   labels:
     - "lab.solution=CORD"
@@ -34,7 +34,7 @@
   restart: unless-stopped
 
 switchq:
-  image: "{{ docker.registry }}/cord-maas-switchq:{{ docker.image_version }}"
+  image: "docker-registry:5000/cord-maas-switchq:{{ docker.image_version }}"
   container_name: switchq
   labels:
     - "lab.solution=CORD"
@@ -51,7 +51,7 @@
   restart: unless-stopped
 
 automation:
-  image: "{{ docker.registry }}/cord-maas-automation:{{ docker.image_version }}"
+  image: "docker-registry:5000/cord-maas-automation:{{ docker.image_version }}"
   container_name: automation
   labels:
     - "lab.solution=CORD"
diff --git a/roles/maas/templates/harvest-compose.yml.j2 b/roles/maas/templates/harvest-compose.yml.j2
index 34aa774..33ca119 100644
--- a/roles/maas/templates/harvest-compose.yml.j2
+++ b/roles/maas/templates/harvest-compose.yml.j2
@@ -1,5 +1,5 @@
 harvester:
-    image: "{{ docker.registry }}/cord-dhcp-harvester:{{ docker.image_version }}"
+    image: "docker-registry:5000/cord-dhcp-harvester:{{ docker.image_version }}"
     container_name: harvester
     restart: always
     labels:
diff --git a/roles/registry/tasks/main.yml b/roles/registry/tasks/main.yml
index c67924d..1453eef 100644
--- a/roles/registry/tasks/main.yml
+++ b/roles/registry/tasks/main.yml
@@ -1,4 +1,14 @@
+- name: Ensure Hostname Resolution
+  become: yes
+  lineinfile:
+    dest: /etc/hosts
+    line: 127.0.0.1 docker-registry
+    owner: root
+    group: root
+    mode: 0644
+
 - name: Directories are present
+  become: yes
   file:
     path: "{{ item }}"
     state: directory
@@ -8,11 +18,21 @@
   tags: [registry]
 
 - name: Configuration is copied
+  become: yes
   copy:
     src: mirror-config.yml
     dest: /data/registry-mirror/conf/config.yml
   tags: [registry]
 
+- name: Ensure Directories
+  become: yes
+  file:
+    path: /etc/maas
+    state: directory
+    owner: root
+    group: root
+    mode: 0755
+
 - name: Local Docker Registry
   become: yes
   template: