CORD-714
Update ansible playbook names
add cord_profile flavor config
add cord_dir for copy destination, parameterize
make user/pass specific to the prod node
use headnode/common as top level config keys
fix inventory template
ignore generated files, remove cord-app-build which is vestigial
use ~/cord instead of ~/opencord for repo
fix variable
create cord_profile in /opt
renamed diag playbook
fix variables

Change-Id: If7d3fbdd6a2fc5bbf52770dcf2f97e5cac420746
diff --git a/.gitignore b/.gitignore
index 5de9569..774a54c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,6 @@
 # sub repos
 platform-install
 maas
+
+# generated config
+genconfig/*
diff --git a/ansible/cord-inv b/ansible/cord-inv
new file mode 100644
index 0000000..c0ec4c8
--- /dev/null
+++ b/ansible/cord-inv
@@ -0,0 +1,6 @@
+[head]
+${headnode_ip} ansible_user=${headnode_user} ansible_ssh_pass=${headnode_pass} ansible_port=${headnode_port}
+
+[compute]
+
+
diff --git a/ansible/prod-inv b/ansible/prod-inv
deleted file mode 100644
index 4fe6f8d..0000000
--- a/ansible/prod-inv
+++ /dev/null
@@ -1,6 +0,0 @@
-[head]
-${prod}
-
-[compute]
-
-
diff --git a/build.gradle b/build.gradle
index 25f70c5..7c76ce8 100644
--- a/build.gradle
+++ b/build.gradle
@@ -71,8 +71,8 @@
         ? project.getProperty('targetReg')
         : config.docker && config.docker.registry
             ? config.docker.registry
-            : config.seedServer.ip
-                ? config.seedServer.ip + ":5000"
+            : config.headnode.ip
+                ? config.headnode.ip + ":5000"
                 : 'localhost:5000'
 
     // The tag used to tag the docker images push to the target registry
@@ -115,12 +115,6 @@
                     'name':     'xosproject/xos-postgres',
                     'digest':   'sha256:f2d31a50b8af7434ab07b1e54e99c1ff1e10d77d16a46e5d6933d3c0528f4820'
             ],
-            'xosproject/cord-app-build': [
-                    'type':     'image',
-                    'upstream': upstreamReg,
-                    'name':     'xosproject/cord-app-build',
-                    'digest':   'sha256:528c6ac3a87609779035857a7b1cf9fab8e046e7ac259d72cf275f1c46d7416e'
-            ],
             'xosproject/xos-base': [
                     'type':     'image',
                     'upstream': upstreamReg,
@@ -144,16 +138,19 @@
 
 // ---------------- Useful tasks ----------------
 
-task copyAnsibleInventory(type: Copy) {
-  from 'platform-install/inventory/templates/single-prod'
-    into 'platform-install/inventory'
+task writeInventory(type: Copy) {
+  from 'ansible/cord-inv'
+    into 'genconfig'
     expand([
-        prod: config.seedServer.ip,
+        headnode_ip: config.headnode.ip,
+        headnode_user: config.headnode.ansible_user,
+        headnode_pass: config.headnode.ansible_ssh_pass,
+        headnode_port: config.headnode.ansible_ssh_port,
     ])
 }
 
 task writeYamlConfig {
-  def outvar = config.seedServer
+  def outvar = config.common
   def outfilename = "genconfig/config.yml"
 
   DumperOptions options = new DumperOptions()
@@ -170,13 +167,6 @@
   outfile.close()
 }
 
-task writeProdInventory(type: Copy) {
-  from 'ansible/prod-inv'
-    into 'genconfig'
-    expand([
-        prod: config.seedServer.ip,
-    ])
-}
 
 task fetchUpstreamImages {
     comps.each { name, spec -> if (spec.type == 'image') { dependsOn "fetch" + name } }
@@ -207,70 +197,70 @@
 
 task CopyCord(type: Exec) {
   dependsOn writeYamlConfig
-  dependsOn writeProdInventory
+  dependsOn writeInventory
 
   executable = "ansible"
-  args = [ "-i", "genconfig/prod-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "synchronize", "-a", "src='../../' dest='/opt/cord'", "head" ]
+  args = [ "-i", "genconfig/cord-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "synchronize", "-a", "src='../../' dest='$config.common.cord_dir'", "head" ]
 }
 
 task ChownCord(type: Exec) {
   dependsOn CopyCord
 
   executable = "ansible"
-  args = [ "-i", "genconfig/prod-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "file", "-a", "state='directory' dest='/opt/cord' recurse='yes' owner='$config.seedServer.ansible_user'", "head" ]
+  args = [ "-i", "genconfig/cord-inv", "-b", "--extra-vars", "@./genconfig/config.yml", "-m", "file", "-a", "state='directory' dest='$config.common.cord_dir' recurse='yes' owner='$config.headnode.ansible_user'", "head" ]
 }
 
 task PIprepPlatform(type: Exec) {
   dependsOn CopyCord
   dependsOn ChownCord
 
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-prep-platform.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml prep-platform-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task PIdeployOpenStack (type: Exec) {
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-openstack.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml deploy-openstack-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task PIdeployONOS (type: Exec) {
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-onos.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml deploy-onos-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task PIdeployXOS (type: Exec) {
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-deploy-xos.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml deploy-xos-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task PIsetupAutomation (type: Exec) {
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-automation.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml cord-automation-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task PIrunDiag (type: Exec) {
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-diag-playbook.yml"
+  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml collect-diag-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 task postDeployTests (type: Exec) {
 
-  def ansible_cmd = "cd /opt/cord/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @/opt/cord/build/genconfig/config.yml cord-post-deploy-playbook.yml"
+  def ansible_cmd = "cd $config.common.cord_dir/build/platform-install; ansible-playbook -i inventory/head-localhost --extra-vars @$config.common.cord_dir/build/genconfig/config.yml pod-test-playbook.yml"
 
   executable = "ssh"
-  args = ["-p", "$config.seedServer.ansible_ssh_port", "$config.seedServer.ansible_user@$config.seedServer.ip", ansible_cmd ]
+  args = ["-p", "$config.headnode.ansible_ssh_port", "$config.headnode.ansible_user@$config.headnode.ip", ansible_cmd ]
 }
 
 project('onos-apps').publishMavenRepoImage.dependsOn project(':maas').prime
diff --git a/config/cord_in_a_box.yml b/config/cord_in_a_box.yml
index 3743d3b..27b92cb 100644
--- a/config/cord_in_a_box.yml
+++ b/config/cord_in_a_box.yml
@@ -5,15 +5,21 @@
 ---
 debug: false
 
-seedServer:
+# this is used to generate the genconfig/cord-inv file
+headnode:
   ip: '10.100.198.201'
-
-  # User name and password used by Ansible to connect to the host for remote
-  # provisioning
   ansible_user: 'vagrant'
   ansible_ssh_pass: 'vagrant'
   ansible_ssh_port: 22
 
+common:
+  # all of these are written to genconfig/config.yml, and needs a rework
+
+  # set to the "flavor" of cord you want to install
+  cord_profile: 'rcord'
+  cord_dir: '/opt/cord'
+  cord_profile_dir: '/opt/cord_profile'
+
   # Specifies tasks within the head node provisioning not to execute, including:
   #
   # switch_support -   don't download the switch ONL images as there are no
@@ -56,3 +62,4 @@
   fabric:
     network: '10.6.1.1/24'
     management: '10.1.0.0/24'
+
diff --git a/config/default.yml b/config/default.yml
index e47182a..1003721 100644
--- a/config/default.yml
+++ b/config/default.yml
@@ -5,15 +5,15 @@
 ---
 debug: false
 
-seedServer:
+# this is used to generate the genconfig/cord-inv file
+headnode:
   ip: '10.100.198.201'
-
-  # User name and password used by Ansible to connect to the host for remote
-  # provisioning
   ansible_user: 'vagrant'
   ansible_ssh_pass: 'vagrant'
   ansible_ssh_port: 22
 
+common:
+
   # Specifies tasks within the head node provisioning not to execute, including:
   #
   # switch_support -   don't download the switch ONL images as there are no
diff --git a/config/onlab_develop_pod.yml b/config/onlab_develop_pod.yml
index ea05cc1..f68bbfe 100644
--- a/config/onlab_develop_pod.yml
+++ b/config/onlab_develop_pod.yml
@@ -1,14 +1,16 @@
 # Deployment configuration for a physical hardware POD
 ---
-seedServer:
+
+# this is used to generate the genconfig/cord-inv file
+headnode:
   ip: '10.90.0.251'
-  # User name and password used by Ansible to connect to the host for remote
-  # provisioning. These default values are used for automated testing, change
-  # with care.
   ansible_user: 'cord'
   ansible_ssh_pass: 'cord'
   ansible_ssh_port: 22
 
+common:
+  # all of these are written to genconfig/config.yml, and needs a rework
+
   # Network address information for the head node:
   #
   # fabric_ip     - the IP address and mask bits to be used to configure the network
diff --git a/config/sample.yml b/config/sample.yml
index d3a261a..82ab6b4 100644
--- a/config/sample.yml
+++ b/config/sample.yml
@@ -1,15 +1,14 @@
 # Deployment configuration for a phyical hardware POD
 ---
-seedServer:
-  # IP address of the head node
-  ip: '10.90.0.2'
 
-  # User name, password, and ssh port used by Ansible to connect to the host for remote
-  # provisioning
+headnode:
+  ip: '10.90.0.2'
   ansible_user: 'ubuntu'
   ansible_ssh_pass: 'ubuntu'
   ansible_ssh_port: 22
 
+common:
+
   # Network address information for the head node:
   #
   # fabric_ip     - the IP address and mask bits to be used to configure the network
diff --git a/scripts/cord-in-a-box.sh b/scripts/cord-in-a-box.sh
index 5b72c4e..0d22dd4 100755
--- a/scripts/cord-in-a-box.sh
+++ b/scripts/cord-in-a-box.sh
@@ -2,7 +2,7 @@
 
 set -e
 
-CORDDIR=~/opencord
+CORDDIR=~/cord
 VMDIR=/cord/build/
 CONFIG=config/cord_in_a_box.yml
 SSHCONFIG=~/.ssh/config
@@ -107,8 +107,8 @@
   cd $CORDDIR/build
 
   # SSH config saved earlier allows us to connect to VM without running 'vagrant'
-  ssh corddev "cd /cord/build; ./gradlew fetch"
-  ssh corddev "cd /cord/build; ./gradlew buildImages"
+  ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG fetch"
+  ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG buildImages"
   ssh corddev "cd /cord/build; ping -c 3 prod; ./gradlew -PdeployConfig=$VMDIR/$CONFIG -PtargetReg=10.100.198.201:5000 publish"
   ssh corddev "cd /cord/build; ./gradlew -PdeployConfig=$VMDIR/$CONFIG deploy"
 }