Merge "CORD-536 updated to support the setting of repo via vars"
diff --git a/roles/xos-vm-install/defaults/main.yml b/roles/xos-vm-install/defaults/main.yml
index 42723d9..0944416 100644
--- a/roles/xos-vm-install/defaults/main.yml
+++ b/roles/xos-vm-install/defaults/main.yml
@@ -1,5 +1,7 @@
 ---
 
+orchestration_dest: "~"
+
 xos_repo_url: "https://gerrit.opencord.org/xos"
 xos_repo_dest: "~/xos"
 xos_repo_branch: "HEAD"
diff --git a/roles/xos-vm-install/files/xos-setup-cord-pod-playbook.yml b/roles/xos-vm-install/files/xos-setup-cord-pod-playbook.yml
index 5b646a5..cc5b955 100644
--- a/roles/xos-vm-install/files/xos-setup-cord-pod-playbook.yml
+++ b/roles/xos-vm-install/files/xos-setup-cord-pod-playbook.yml
@@ -21,12 +21,32 @@
        - python-keystoneclient
        - python-glanceclient
 
+    - name: Check to see if xos_install/orchestration directory exists
+      local_action: stat path="{{ playbook_dir }}/xos_install/orchestration"
+      register: orchestration
+
+     # Two methods to install:
+     #   1) If running from cord-in-a-box, then xos_install/orchestration will
+     #      be populated with the checked-out xos repositories, and we can
+     #      now copy them to the XOS VM.
+     #   2) If not running from cord-in-a-box, then xos_install will not
+     #      exist, and we will check out the repos using git.
+
+    - name: Copy repositories to the XOS VM
+      synchronize:
+           src: "{{ playbook_dir }}/xos_install/orchestration/"
+           dest: "{{ orchestration_dest }}"
+      when:
+           orchestration.stat.exists == True
+
     - name: Clone XOS repo
       git:
         repo={{ xos_repo_url }}
         dest={{ xos_repo_dest }}
         version={{ xos_repo_branch }}
         force=yes
+      when:
+          orchestration.stat.exists == False
 
     - name: Clone service-profile repo
       git:
@@ -34,6 +54,8 @@
         dest={{ service_profile_repo_dest }}
         version={{ service_profile_repo_branch }}
         force=yes
+      when:
+        orchestration.stat.exists == False
 
     - name: Copy over SSH keys
       copy:
diff --git a/roles/xos-vm-install/tasks/main.yml b/roles/xos-vm-install/tasks/main.yml
index 5ee7905..1f704c6 100644
--- a/roles/xos-vm-install/tasks/main.yml
+++ b/roles/xos-vm-install/tasks/main.yml
@@ -8,6 +8,35 @@
     src=xos-setup-vars.yml.j2
     dest={{ ansible_user_dir }}/xos-setup-vars.yml
 
+- name: Check to see if orchestration directory exists
+  local_action: stat path="{{ playbook_dir }}/../../orchestration"
+  register: orchestration
+
+- name: Make xos_install directory
+  file: path="{{ ansible_user_dir }}/xos_install" state=directory
+  when: orchestration.stat.exists == True
+
+- name: Copy repositories to the head node
+  synchronize:
+      src: "{{ playbook_dir }}/../../orchestration"
+      dest: "{{ ansible_user_dir }}/xos_install/"
+  when:
+      orchestration.stat.exists == True
+
+- name: Check to see if onos_apps directory exists
+  local_action: stat path="{{ playbook_dir }}/../../onos-apps/apps"
+  register: onos_apps
+
+- name: Copy in onos-apps that have XOS code
+  synchronize:
+      src: "{{ playbook_dir }}/../../onos-apps/apps/{{ item }}"
+      dest: "{{ ansible_user_dir }}/xos_install/orchestration/xos_services/"
+  with_items:
+      - vtn
+      - olt
+  when:
+      (orchestration.stat.exists == True) and (onos_apps.stat.exists == True)
+
 - name: Copy over XOS ansible playbook
   copy:
     src=xos-setup-{{ xos_configuration }}-playbook.yml
diff --git a/roles/xos-vm-install/templates/xos-setup-vars.yml.j2 b/roles/xos-vm-install/templates/xos-setup-vars.yml.j2
index de7838e..da40258 100644
--- a/roles/xos-vm-install/templates/xos-setup-vars.yml.j2
+++ b/roles/xos-vm-install/templates/xos-setup-vars.yml.j2
@@ -1,5 +1,7 @@
 ---
 
+orchestration_dest: "{{ orchestration_dest }}"
+
 xos_repo_url: "{{ xos_repo_url }}"
 xos_repo_dest: "{{ xos_repo_dest }}"
 xos_repo_branch: "{{ xos_repo_branch }}"