CORD-1394 Unify build environment paths

Change-Id: I433d5ae95c9cc540d5586da5ca55b889d8fb1f81
diff --git a/README.md b/README.md
index 9dd48e9..ad63d6a 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@
 tool, [Ansible](https://docs.ansible.com/ansible/index.html), and
 [Docker](https://www.docker.com/), as well as make a checkout of the CORD
 [manifest](https://gerrit.opencord.org/gitweb?p=manifest.git;a=blob;f=default.xml)
-into `~/cord`.
+into `/opt/cord`.
 
 You can specify which gerrit changesets you would like repo to checkout using
 the `-b` option on the script [as documented
@@ -44,8 +44,7 @@
 Once you log back in, you may want to run `tmux` to maintain a server-side
 session you can reconnect to, in case of network trouble.
 
-All of the commands below assume you're in the `cord/build/platform-install`
-directory.
+All of the commands below assume you're in the `/opt/cord/build/platform-install` directory.
 
 ### Creating a development environment on you machine
 
@@ -61,7 +60,7 @@
 test the outcome.
 
 Once the `vm` is created you can connect to it with `vagrant ssh head-node` and
-then from the `~/cord/build/platform-install` execute the profile you are
+then from the `/opt/cord/build/platform-install` execute the profile you are
 interested in.  For instance you can spin up the `frontend` configuration with:
 `ansible-playbook -i inventory/frontend deploy-xos-playbook.yml`.
 
diff --git a/Vagrantfile b/Vagrantfile
index 35b4f53..c401275 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -3,50 +3,23 @@
   config.vm.box = "ubuntu/trusty64"
 
   # share the folder
-  config.vm.synced_folder "../../", "/home/vagrant/cord/", create: true
-  config.vm.synced_folder "./cord_profile", "/home/vagrant/cord_profile/", create: true
+  config.vm.synced_folder "../../", "/opt/cord/", create: true
+  config.vm.synced_folder "./cord_profile", "/opt/cord_profile/", create: true
   config.vm.synced_folder ".", "/vagrant", disabled: true
 
   # set the frontend vm
   config.vm.define "head-node" do |d|
-    d.vm.network "forwarded_port", guest: 9999, host: 9999
-    d.vm.network "forwarded_port", guest: 6379, host: 6379
     d.vm.network "private_network", ip: "192.168.46.100"
     d.vm.provider "virtualbox" do |vb|
-      vb.memory = "4096"
+      vb.memory = "2048"
       vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
       vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
     end
   end
 
-  config.vm.provision "shell", privileged: false, inline: <<-SHELL
-    # Setup CORD tools
-    curl -o ~/cord-bootstrap.sh https://raw.githubusercontent.com/opencord/platform-install/master/scripts/cord-bootstrap.sh
-    bash cord-bootstrap.sh
-    ssh-keygen -t rsa -N "" -f .ssh/id_rsa
-    cp ~/.ssh/id_rsa node_key
-
-    # Install apache
-    sudo apt-get update
-    sudo apt-get install -y apache2 libapache2-mod-fastcgi apache2-mpm-worker
-    sudo a2enmod proxy_http
-    sudo a2enmod headers
-    sudo a2enmod rewrite
-    sudo a2enmod proxy_wstunnel
-
-    # Copy apache conf
-    sudo cp /home/vagrant/cord/build/platform-install/roles/apache-proxy/files/cord-http.conf /etc/apache2/conf-enabled/cord-http.conf
-
-    # Reload Apache
-    sudo service apache2 reload
-
-    # Add hosts
-    echo "127.0.0.1 xos" | sudo tee --append /etc/hosts > /dev/null
-    echo "127.0.0.1 xos-gui" | sudo tee --append /etc/hosts > /dev/null
-    echo "127.0.0.1 xos-ws" | sudo tee --append /etc/hosts > /dev/null
-    echo "127.0.0.1 xos-chameleon" | sudo tee --append /etc/hosts > /dev/null
-    echo "127.0.0.1 xos-core" | sudo tee --append /etc/hosts > /dev/null
-    echo "127.0.0.1 consul" | sudo tee --append /etc/hosts > /dev/null
-  SHELL
-
- end
+  config.vm.provision :shell, privileged: false, path: "./scripts/cord-bootstrap.sh"
+  config.vm.provision "ansible_local" do |ansible|
+    ansible.provisioning_path = "/opt/cord/build/platform-install"
+    ansible.playbook = "bootstrap-dev-env.yml"
+  end
+end
diff --git a/bootstrap-dev-env.yml b/bootstrap-dev-env.yml
new file mode 100644
index 0000000..cb8710e
--- /dev/null
+++ b/bootstrap-dev-env.yml
@@ -0,0 +1,4 @@
+- name: Bootstrap dev env
+  hosts: all
+  roles:
+    - dev-env
diff --git a/copy-profile-playbook.yml b/copy-profile-playbook.yml
index 70d8dfb..17beb92 100644
--- a/copy-profile-playbook.yml
+++ b/copy-profile-playbook.yml
@@ -11,11 +11,6 @@
         - "profile_manifests/{{ cord_profile }}.yml"
         - profile_manifests/local_vars.yml
 
-- name: Set hostvars with defaults for each node
-  hosts: head, config
-  roles:
-    - hostvars-defaults
-
 - name: Copy cord_profile to head node from config node
   hosts: head
   roles:
diff --git a/profile_manifests/frontend.yml b/profile_manifests/frontend.yml
index eb8d7a9..f67fad5 100644
--- a/profile_manifests/frontend.yml
+++ b/profile_manifests/frontend.yml
@@ -4,10 +4,6 @@
 site_name: frontend
 deployment_type: "Frontend Mock"
 
-# head == config for frontend mocks
-head_cord_profile_dir: "{{ ansible_user_dir + '/cord_profile' }}"
-head_cord_dir: "{{ ansible_user_dir + '/cord' }}"
-
 frontend_only: True
 use_redis: True
 use_openstack: False
diff --git a/profile_manifests/mock-rcord.yml b/profile_manifests/mock-rcord.yml
index bf7a47b..da809d3 100644
--- a/profile_manifests/mock-rcord.yml
+++ b/profile_manifests/mock-rcord.yml
@@ -12,10 +12,6 @@
 
 credentials_dir: "{{ playbook_dir }}/credentials"
 
-# head == config for mocks
-head_cord_profile_dir: "{{ ansible_user_dir + '/cord_profile' }}"
-head_cord_dir: "{{ ansible_user_dir + '/cord' }}"
-
 frontend_only: True
 use_openstack: False
 use_vtn: True
diff --git a/roles/api-tests/defaults/main.yml b/roles/api-tests/defaults/main.yml
index 8602670..1ca9045 100644
--- a/roles/api-tests/defaults/main.yml
+++ b/roles/api-tests/defaults/main.yml
@@ -1,5 +1,4 @@
 ---
 # api-tests/defaults/main.yml
 
-config_cord_dir: "{{ ansible_user_dir ~ '/cord' }}"
-
+config_cord_dir: "/opt/cord"
diff --git a/roles/copy-cord/defaults/main.yml b/roles/copy-cord/defaults/main.yml
index 2b0f313..b3ac08a 100644
--- a/roles/copy-cord/defaults/main.yml
+++ b/roles/copy-cord/defaults/main.yml
@@ -1,5 +1,5 @@
 ---
 # copy-cord/defaults/main.yml
 
-config_cord_dir: "{{ ansible_user_dir ~ '/cord' }}"
+config_cord_dir: "/opt/cord"
 head_cord_dir: "/opt/cord"
diff --git a/roles/copy-profile/defaults/main.yml b/roles/copy-profile/defaults/main.yml
index 6f7b645..e9d6fb4 100644
--- a/roles/copy-profile/defaults/main.yml
+++ b/roles/copy-profile/defaults/main.yml
@@ -1,5 +1,5 @@
 ---
 # copy-profile/defaults/main.yml
 
-config_cord_profile_dir: "{{ ansible_user_dir ~ '/cord_profile' }}"
+config_cord_profile_dir: "/opt/cord_profile"
 head_cord_profile_dir: "/opt/cord_profile"
diff --git a/roles/copy-profile/tasks/main.yml b/roles/copy-profile/tasks/main.yml
index 3434c27..c206a3f 100644
--- a/roles/copy-profile/tasks/main.yml
+++ b/roles/copy-profile/tasks/main.yml
@@ -3,7 +3,7 @@
 
 - name: Copy (sync) the cord_profile directory structure to head node
   synchronize:
-    src: "{{ hostvars[groups['config'][0]]['config_cord_profile_dir'] }}/"
+    src: "{{ config_cord_profile_dir }}/"
     dest: "{{ head_cord_profile_dir }}/"
     delete: yes
 
diff --git a/roles/cord-profile/defaults/main.yml b/roles/cord-profile/defaults/main.yml
index c7bf7aa..82d517f 100644
--- a/roles/cord-profile/defaults/main.yml
+++ b/roles/cord-profile/defaults/main.yml
@@ -2,7 +2,7 @@
 # cord-profile/defaults/main.yml
 
 # where the cord_profile directory is on the config node
-config_cord_profile_dir: "{{ ansible_user_dir ~ '/cord_profile' }}"
+config_cord_profile_dir: "/opt/cord_profile"
 
 pki_dir: "{{ playbook_dir }}/pki"
 ssh_pki_dir: "{{ playbook_dir }}/ssh_pki"
diff --git a/roles/dev-env/tasks/main.yml b/roles/dev-env/tasks/main.yml
new file mode 100644
index 0000000..2189b3f
--- /dev/null
+++ b/roles/dev-env/tasks/main.yml
@@ -0,0 +1,59 @@
+---
+# dev-env/tasks/main.yml
+
+- name: Create SSH keypair
+  user:
+    name: "{{ ansible_env.USER }}"
+    generate_ssh_key: yes
+    ssh_key_bits: 2048
+
+- name: Create node_key
+  copy:
+    src: "{{ ansible_env.HOME }}/.ssh/id_rsa.pub"
+    dest: "{{ ansible_env.HOME }}/node_key"
+
+- name: Install Apache
+  become: yes
+  apt:
+    name: "{{ item }}"
+    update_cache: yes
+  with_items:
+  - "apache2"
+  - "libapache2-mod-fastcgi"
+  - "apache2-mpm-worker"
+
+- name: Configure Apache
+  become: yes
+  apache2_module:
+    name: "{{ item }}"
+    state: present
+  with_items:
+  - "proxy_http"
+  - "headers"
+  - "rewrite"
+  - "proxy_wstunnel"
+
+- name: Copy Apache conf
+  become: yes
+  copy:
+    src: "roles/apache-proxy/files/cord-http.conf"
+    dest: "/etc/apache2/conf-enabled/cord-http.conf"
+
+- name: Reload Apache
+  become: yes
+  service:
+    name: apache2
+    state: reloaded
+
+- name: Add hosts
+  become: yes
+  lineinfile:
+    dest: /etc/hosts
+    line: "{{ item }}"
+  with_items:
+  - "127.0.0.1 xos"
+  - "127.0.0.1 xos-gui"
+  - "127.0.0.1 xos-ws"
+  - "127.0.0.1 xos-chameleon"
+  - "127.0.0.1 xos-core"
+  - "127.0.0.1 consul"
diff --git a/roles/hostvars-defaults/defaults/main.yml b/roles/hostvars-defaults/defaults/main.yml
deleted file mode 100644
index 479c662..0000000
--- a/roles/hostvars-defaults/defaults/main.yml
+++ /dev/null
@@ -1,31 +0,0 @@
----
-# hostvars-defaults/defaults/main.yml
-
-# default values
-config_cord_dir: "{{ ansible_user_dir ~ '/cord' }}"
-build_cord_dir: "{{ playbook_dir ~ '/../..' }}"
-head_cord_dir: "/opt/cord"
-
-config_cord_profile_dir: "{{ ansible_user_dir ~ '/cord_profile' }}"
-head_cord_profile_dir: "/opt/cord_profile"
-
-head_onos_cord_dir: "/opt/onos-cord/"
-head_onos_fabric_dir: "/opt/onos_fabric/"
-
-# list of all defaults to set as hostvars
-hostvars_defaults_dict:
-  - key: config_cord_dir
-    val: "{{ config_cord_dir }}"
-  - key: build_cord_dir
-    val: "{{ build_cord_dir }}"
-  - key: head_cord_dir
-    val: "{{ head_cord_dir }}"
-  - key: config_cord_profile_dir
-    val: "{{ config_cord_profile_dir }}"
-  - key: head_cord_profile_dir
-    val: "{{ head_cord_profile_dir }}"
-  - key: head_onos_cord_dir
-    val: "{{ head_onos_cord_dir }}"
-  - key: head_onos_fabric_dir
-    val: "{{ head_onos_fabric_dir }}"
-
diff --git a/roles/hostvars-defaults/tasks/main.yml b/roles/hostvars-defaults/tasks/main.yml
deleted file mode 100644
index e16b593..0000000
--- a/roles/hostvars-defaults/tasks/main.yml
+++ /dev/null
@@ -1,14 +0,0 @@
----
-# hostvars-defaults/tasks/main.yml
-# Sets default variables in multiple hosts to allow them to accessed on other
-# hosts via the hostvars['otherhost']['defaultvar']
-
-- name: List host group specific values of default variables
-  debug:
-    msg: "{{ item.key }}:{{ item.val }}"
-  with_items: "{{ hostvars_defaults_dict }}"
-
-- name: Set hostvars as facts to persist them
-  set_fact: {"{{ item.key }}":"{{ item.val }}"}
-  with_items: "{{ hostvars_defaults_dict }}"
-
diff --git a/roles/monitoringservice-config/defaults/main.yml b/roles/monitoringservice-config/defaults/main.yml
index 2e9d196..337a459 100644
--- a/roles/monitoringservice-config/defaults/main.yml
+++ b/roles/monitoringservice-config/defaults/main.yml
@@ -2,7 +2,7 @@
 # monitoringservice-config/defaults/main.yml
 
 #paths
-config_cord_dir: "{{ ansible_user_dir ~ '/cord' }}"
+config_cord_dir: "/opt/cord"
 head_cord_dir: "/opt/cord"
 
 head_cord_profile_dir: "/opt/cord_profile"
diff --git a/roles/platform-check/defaults/main.yml b/roles/platform-check/defaults/main.yml
index f7c291c..8e48e41 100644
--- a/roles/platform-check/defaults/main.yml
+++ b/roles/platform-check/defaults/main.yml
@@ -1,7 +1,7 @@
 ---
 # platform-check/defaults/main.yml
 
-config_cord_profile_dir: "{{ ansible_user_dir ~ '/cord_profile' }}"
+config_cord_profile_dir: "/opt/cord_profile"
 head_onos_cord_dir: "/opt/onos-cord/"
 
 xos_ui_port: 9000
diff --git a/roles/repo/defaults/main.yml b/roles/repo/defaults/main.yml
index 521d097..301af14 100644
--- a/roles/repo/defaults/main.yml
+++ b/roles/repo/defaults/main.yml
@@ -1,7 +1,7 @@
 ---
 # repo/defaults/main.yml
 
-config_cord_dir: "{{ ansible_user_dir ~ '/cord' }}"
+config_cord_dir: "/opt/cord"
 repo_dl_url: "https://storage.googleapis.com/git-repo-downloads/repo"
 
 # This is for repo v1.23, and will change, as repo_dl_url unfortunately lacks a version...
diff --git a/scripts/cord-bootstrap.sh b/scripts/cord-bootstrap.sh
index 5b5c697..2b95d71 100644
--- a/scripts/cord-bootstrap.sh
+++ b/scripts/cord-bootstrap.sh
@@ -5,7 +5,7 @@
 set -e
 set -x
 
-CORDDIR=~/cord
+CORDDIR=/opt/cord
 
 function bootstrap() {