Create inventory, setup head node

Change-Id: I4604ade8413e05178922691b39c40c1397f78234
diff --git a/build.gradle b/build.gradle
index 519db66..92c7c39 100644
--- a/build.gradle
+++ b/build.gradle
@@ -56,6 +56,18 @@
 
 }
 
+task copyAnsibleInventory(type: Copy) {
+    File configFile = new File(deployConfig)
+    def yaml = new Yaml()
+    def config = yaml.load(configFile.newReader())
+
+    from 'inventory/templates/single-prod'
+    into 'inventory'
+    expand([
+  prod: config.seedServer.ip,
+    ])
+}
+
 // ------------- PlaceHolders ----------------
 
 task updateDocker (type: Exec) {
@@ -64,7 +76,7 @@
 
 task prime {
     // TODO this is a place-holder.
-    dependsOn updateDocker
+    // dependsOn updateDocker
     doFirst {
         println "Using deployment config: $deployConfig"
         File configFile = new File(deployConfig)
@@ -103,15 +115,55 @@
 tasks.addRule(new DockerTagRule(project))
 tasks.addRule(new GitSubmoduleUpdateRule(project))
 
-task deploy {
-    // TODO this is a place-holder.
-    doFirst {
-        println "Using deployment config: $deployConfig"
-        File configFile = new File(deployConfig)
-        def yaml = new Yaml()
-        def config = yaml.load(configFile.newReader())
-        println "Config: $config"
-        println "Access some data in config:\n\tSeed server IP=${config.seedServer.ip}"
-    }
-}
+task deploy (type: Exec) {
+    dependsOn copyAnsibleInventory
 
+    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", "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")
+    }
+
+    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", " ")) << "cord-head-playbook.yml"
+}
diff --git a/inventory/templates/single-prod b/inventory/templates/single-prod
new file mode 100644
index 0000000..4fe6f8d
--- /dev/null
+++ b/inventory/templates/single-prod
@@ -0,0 +1,6 @@
+[head]
+${prod}
+
+[compute]
+
+