generate config yaml file instead of long extra-vars parameter

Change-Id: I99c56a415b07ecda4786f8a70a34343d30acad9f
diff --git a/build.gradle b/build.gradle
index 97259c4..c4bdfda 100644
--- a/build.gradle
+++ b/build.gradle
@@ -16,6 +16,7 @@
 
 import org.opencord.gradle.rules.*
 import org.yaml.snakeyaml.Yaml
+import org.yaml.snakeyaml.DumperOptions
 
 allprojects {
     apply plugin: 'base'
@@ -58,7 +59,6 @@
     def yaml = new Yaml()
     config = yaml.load(configFile.newReader())
 
-
     // Target registry to be used to publish docker images needed for deployment
     targetReg = project.hasProperty('targetReg')
         ? project.getProperty('targetReg')
@@ -91,55 +91,40 @@
 }
 
 task copyAnsibleInventory(type: Copy) {
-    from 'inventory/templates/single-prod'
+  from 'inventory/templates/single-prod'
     into 'inventory'
     expand([
-  prod: config.seedServer.ip,
+        prod: config.seedServer.ip,
     ])
 }
 
+task writeYamlConfig {
+  def outvar = config.seedServer
+  def outfilename = "genconfig/deployconf.yml"
+
+  DumperOptions options = new DumperOptions()
+
+  options.setExplicitStart(true);
+  options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
+  options.setPrettyFlow(true);
+  options.setIndent(2);
+
+  def yaml = new Yaml(options)
+  Writer outfile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfilename), "utf-8"))
+
+  yaml.dump(outvar, outfile)
+
+  outfile.close()
+}
+
 // ------------- PlaceHolders ----------------
 
-task updateDocker (type: Exec) {
-    commandLine 'sudo', 'utils/enable-remote-docker-registry', "$targetReg"
-}
-
 task prime {
     // TODO this is a place-holder.
-    // dependsOn updateDocker
 }
 
 // ---------------- Useful tasks ----------------
 
-List.metaClass.asParam = { prefix, sep ->
-  if (delegate.size() == 0) {
-    ""
-  }
-  String result = "--" + prefix + "="
-  String p = ""
-  delegate.each {
-    result += p + "${it}"
-    p = sep
-  }
-  result
-}
-
-List.metaClass.p = { value, name ->
-  if (value != null && value != "") {
-      delegate << name + "=" + value
-  } else {
-      delegate
-  }
-}
-
-List.metaClass.p = { spec ->
-  if (spec != null && spec != "") {
-      delegate += spec
-  } else {
-      delegate
-  }
-}
-
 task fetch << {
     logger.info 'Platform install has nothing to fetch'
 }
@@ -163,229 +148,32 @@
 
 task prepPlatform(type: Exec) {
     dependsOn copyAnsibleInventory
+    dependsOn writeYamlConfig
 
     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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-prep-platform.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-prep-platform.yml"]
 }
 
 task deployOpenStack (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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-openstack.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-onos.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-deploy-xos.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-automation.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-automation.yml"]
 }
 
 deployOpenStack.mustRunAfter prepPlatform
@@ -402,46 +190,8 @@
 }
 
 task postDeployTests (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")
-        .p("$cordAppVersion", "cord_app_version")
-
-    def skipTags = [].p(config.seedServer.skipTags)
-
-    args = args.p(skipTags.asParam("skip-tags", ",")).p(extraVars.asParam("extra-vars", " ")) << "cord-post-deploy-playbook.yml"
+    args = ["-i", "inventory/single-prod", "--extra-vars", "@../genconfig/deployconf.yml", "cord-post-deploy-playbook.yml"]
 }
+