Break into smaller tasks for easier restart of bad install

Change-Id: Ia255d7b8ca4b0e0b26873853d3c108c4bb70b47a
diff --git a/build.gradle b/build.gradle
index b82f55e..9c462da 100644
--- a/build.gradle
+++ b/build.gradle
@@ -64,7 +64,7 @@
         ? project.getProperty('targetTag')
         : config.docker && config.docker.imageVersion
             ? config.docker.imageVersion
-            : 'candidate'    
+            : 'candidate'
 
     println "targetReg = $targetReg, targetTag = $targetTag"
 
@@ -144,7 +144,7 @@
 tasks.addRule(new DockerTagRule(project))
 tasks.addRule(new GitSubmoduleUpdateRule(project))
 
-task deployPlatform (type: Exec) {
+task prepPlatform(type: Exec) {
     dependsOn copyAnsibleInventory
 
     executable = "ansible-playbook"
@@ -187,12 +187,10 @@
 
     def skipTags = [].p(config.seedServer.skipTags)
 
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-head-playbook.yml"
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-prep-platform.yml"
 }
 
-task deploySingle (type: Exec) {
-    dependsOn copyAnsibleInventory
-
+task deployOpenStack (type: Exec) {
     executable = "ansible-playbook"
     args = ["-i", "inventory/single-prod"]
 
@@ -233,12 +231,155 @@
 
     def skipTags = [].p(config.seedServer.skipTags)
 
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-single-playbook.yml"
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-openstack.yml"
+}
+
+task deployONOS (type: Exec) {
+    executable = "ansible-playbook"
+    args = ["-i", "inventory/single-prod"]
+
+    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")
+            .p(config.seedServer.virtualbox_support, "virtualbox_support")
+            .p(config.seedServer.power_helper_user, "power_helper_user")
+            .p(config.seedServer.power_helper_host, "power_helper_host")
+            .p(config.seedServer.port, "ansible_ssh_port")
+    }
+
+    if (config.otherServers) {
+        extraVars = extraVars.p(config.otherServers.location, "prov_location")
+            .p(config.otherServers.rolesPath, "prov_role_path")
+            .p(config.otherServers.role, "prov_role")
+    }
+
+    extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
+        .p("$targetTag", "deploy_docker_tag")
+
+    def skipTags = [].p(config.seedServer.skipTags)
+
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-onos.yml"
+}
+
+task deployXOS (type: Exec) {
+    executable = "ansible-playbook"
+    args = ["-i", "inventory/single-prod"]
+
+    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")
+            .p(config.seedServer.virtualbox_support, "virtualbox_support")
+            .p(config.seedServer.power_helper_user, "power_helper_user")
+            .p(config.seedServer.power_helper_host, "power_helper_host")
+            .p(config.seedServer.port, "ansible_ssh_port")
+    }
+
+    if (config.otherServers) {
+        extraVars = extraVars.p(config.otherServers.location, "prov_location")
+            .p(config.otherServers.rolesPath, "prov_role_path")
+            .p(config.otherServers.role, "prov_role")
+    }
+
+    extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
+        .p("$targetTag", "deploy_docker_tag")
+
+    def skipTags = [].p(config.seedServer.skipTags)
+
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-xos.yml"
+}
+
+task setupAutomation (type: Exec) {
+    executable = "ansible-playbook"
+    args = ["-i", "inventory/single-prod"]
+
+    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")
+            .p(config.seedServer.virtualbox_support, "virtualbox_support")
+            .p(config.seedServer.power_helper_user, "power_helper_user")
+            .p(config.seedServer.power_helper_host, "power_helper_host")
+            .p(config.seedServer.port, "ansible_ssh_port")
+    }
+
+    if (config.otherServers) {
+        extraVars = extraVars.p(config.otherServers.location, "prov_location")
+            .p(config.otherServers.rolesPath, "prov_role_path")
+            .p(config.otherServers.role, "prov_role")
+    }
+
+    extraVars = extraVars.p("$targetReg", "deploy_docker_registry")
+        .p("$targetTag", "deploy_docker_tag")
+
+    def skipTags = [].p(config.seedServer.skipTags)
+
+    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-automation.yml"
+}
+
+deployOpenStack.mustRunAfter prepPlatform
+deployONOS.mustRunAfter deployOpenStack
+deployXOS.mustRunAfter deployONOS
+setupAutomation.mustRunAfter deployXOS
+
+task deployPlatform {
+     dependsOn prepPlatform
+     dependsOn deployOpenStack
+     dependsOn deployONOS
+     dependsOn deployXOS
+     dependsOn setupAutomation
 }
 
 task postDeployTests (type: Exec) {
-    dependsOn copyAnsibleInventory
-
     executable = "ansible-playbook"
     args = ["-i", "inventory/single-prod"]
 
@@ -281,4 +422,3 @@
 
     args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
 }
-
diff --git a/cord-automation.yml b/cord-automation.yml
new file mode 100644
index 0000000..234785a
--- /dev/null
+++ b/cord-automation.yml
@@ -0,0 +1,22 @@
+---
+# Installs the automation scripts used by MaaS to provision nodes.
+
+- name: Include vars
+  hosts: all
+  tasks:
+    - name: Include variables
+      include_vars: "{{ item }}"
+      with_items:
+        - vars/cord_defaults.yml
+        - vars/cord.yml
+        - vars/example_keystone.yml
+
+- name: Set up Automated Compute Node Provisioning
+  hosts: head
+  roles:
+    - { role: automation-integration, when: on_maas }
+
+- name: Prologue
+  hosts: head
+  roles:
+    - head-prologue
diff --git a/cord-deploy-onos.yml b/cord-deploy-onos.yml
new file mode 100644
index 0000000..eef5ab4
--- /dev/null
+++ b/cord-deploy-onos.yml
@@ -0,0 +1,18 @@
+---
+# Deploys ONOS in Docker containers on the CORD head node
+
+- name: Include vars
+  hosts: all
+  tasks:
+    - name: Include variables
+      include_vars: "{{ item }}"
+      with_items:
+        - vars/cord_defaults.yml
+        - vars/cord.yml
+        - vars/example_keystone.yml
+
+- name: Deploy and start ONOS containers
+  hosts: head
+  roles:
+    - onos-cord-install
+    - onos-fabric-install
diff --git a/cord-deploy-openstack.yml b/cord-deploy-openstack.yml
new file mode 100644
index 0000000..3a0e596
--- /dev/null
+++ b/cord-deploy-openstack.yml
@@ -0,0 +1,31 @@
+---
+# Deploys OpenStack in LXD containers on the CORD head node
+
+- name: Include vars
+  hosts: all
+  tasks:
+    - name: Include variables
+      include_vars: "{{ item }}"
+      with_items:
+        - vars/cord_defaults.yml
+        - vars/cord.yml
+        - vars/example_keystone.yml
+
+- name: Configure head node, create containers
+  hosts: head
+  roles:
+    - { role: head-prep, become: yes }
+    - create-lxd
+
+- name: Start OpenStack install
+  hosts: head
+  roles:
+    - juju-setup
+
+# Put plays here that will execute in parallel to
+# the OpenStack installation
+
+- name: Finish OpenStack install
+  hosts: head
+  roles:
+    - juju-finish
diff --git a/cord-deploy-xos.yml b/cord-deploy-xos.yml
new file mode 100644
index 0000000..29221fb
--- /dev/null
+++ b/cord-deploy-xos.yml
@@ -0,0 +1,24 @@
+---
+# Deploys XOS in Docker containers on the CORD head node
+
+- name: Include vars
+  hosts: all
+  tasks:
+    - name: Include variables
+      include_vars: "{{ item }}"
+      with_items:
+        - vars/cord_defaults.yml
+        - vars/cord.yml
+        - vars/example_keystone.yml
+
+- name: XOS setup
+  hosts: head
+  roles:
+    - { role: xos-build, when: xos_container_rebuild }
+    - xos-install
+
+- name: Start XOS
+  hosts: head
+  roles:
+    - xos-config
+    - xos-head-start
diff --git a/cord-prep-platform.yml b/cord-prep-platform.yml
new file mode 100644
index 0000000..70313f1
--- /dev/null
+++ b/cord-prep-platform.yml
@@ -0,0 +1,33 @@
+---
+# Prepares the CORD head node for installing OpenStack, ONOS, and XOS
+
+- name: Include vars
+  hosts: all
+  tasks:
+    - name: Include variables
+      include_vars: "{{ item }}"
+      with_items:
+        - vars/cord_defaults.yml
+        - vars/cord.yml
+        - vars/example_keystone.yml
+
+- name: DNS Server and apt-cacher-ng Setup
+  hosts: head
+  become: yes
+  roles:
+    - { role: dns-nsd, when: not on_maas }
+    - { role: dns-unbound, when: not on_maas }
+    - apt-cacher-ng
+
+- name: Configure all hosts to use DNS server
+  hosts: all
+  become: yes
+  roles:
+    - { role: dns-configure, when: not on_maas }
+
+- name: Prep systems
+  hosts: all
+  become: yes
+  roles:
+    - common-prep
+    - { role: cloudlab-prep, when: on_cloudlab }