pull the xos-base container from the local registry

Change-Id: I358c0614b53385c4d9725e165a654d4e4a6f8898
diff --git a/roles/xos-vm-install/defaults/main.yml b/roles/xos-vm-install/defaults/main.yml
index 0944416..0be9d5b 100644
--- a/roles/xos-vm-install/defaults/main.yml
+++ b/roles/xos-vm-install/defaults/main.yml
@@ -8,8 +8,13 @@
 
 xos_configuration: "devel"
 
-xos_container_rebuild: True
+xos_container_rebuild: False
 
 service_profile_repo_url: "https://gerrit.opencord.org/p/service-profile.git"
 service_profile_repo_dest: "~/service-profile"
 service_profile_repo_branch: "HEAD"
+
+docker_opts: ""
+docker_tag: "latest"
+docker_registry: "docker.io"
+local_docker_registry: "docker-registry:5000"
diff --git a/roles/xos-vm-install/files/docker.j2 b/roles/xos-vm-install/files/docker.j2
new file mode 100644
index 0000000..48f5c5c
--- /dev/null
+++ b/roles/xos-vm-install/files/docker.j2
@@ -0,0 +1,17 @@
+# Docker Upstart and SysVinit configuration file
+
+# Customize location of Docker binary (especially for development testing).
+#DOCKER="/usr/local/bin/docker"
+
+# Use DOCKER_OPTS to modify the daemon startup options.
+#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
+
+DOCKER_OPTS="{{ docker_opts }}"
+
+#"--insecure-registry 10.1.0.1:5000"
+
+# If you need Docker to use an HTTP proxy, it can also be specified here.
+#export http_proxy="http://127.0.0.1:3128/"
+
+# This is also a handy place to tweak where Docker's temporary files go.
+#export TMPDIR="/mnt/bigdrive/docker-tmp"
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 cc5b955..abb5a30 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
@@ -1,7 +1,6 @@
 ---
 - hosts: xos-1
   remote_user: ubuntu
-
   tasks:
     - name: Include configuration vars
       include_vars: xos-setup-vars.yml
@@ -79,6 +78,32 @@
         dest={{ service_profile_repo_dest }}/{{ xos_configuration }}/images/{{ item.name }}.img
       with_items: "{{ xos_images }}"
 
+    - name: Check to see if registry is reachable
+      command: curl -sf http://docker-registry:5000/
+      ignore_errors: yes
+      register: docker_registry_check
+      tags:
+        - skip_ansible_lint
+
+    - name: Use registry if it is available
+      set_fact:
+         docker_registry: "{{ local_docker_registry }}"
+         docker_opts: "--insecure-registry {{ local_docker_registry }}"
+         docker_tag: "candidate"
+      when: docker_registry_check|succeeded
+
+    - name: Set docker options
+      become: yes
+      template: src=docker.j2 dest=/etc/default/docker
+      register: set_docker_opts
+
+    # Note this needs to be executed now, not as a handler,  as the pull
+    # operations won't succeed without it.
+    - name: restart docker
+      become: yes
+      service: name=docker state=restarted
+      when: set_docker_opts.changed
+
     - name: Pull database and cord-app-build image
       become: yes
       command: docker pull {{ item }}
@@ -93,7 +118,7 @@
       become: yes
       command: docker pull {{ item }}
       with_items:
-        - xosproject/xos-base
+        - "{{ docker_registry }}/xosproject/xos-base:{{ docker_tag }}"
 
     - name: Rebuild XOS containers
       when: xos_container_rebuild
@@ -103,3 +128,4 @@
        - base
 
 
+
diff --git a/roles/xos-vm-install/tasks/main.yml b/roles/xos-vm-install/tasks/main.yml
index 65a368d..7ecf5b3 100644
--- a/roles/xos-vm-install/tasks/main.yml
+++ b/roles/xos-vm-install/tasks/main.yml
@@ -42,6 +42,16 @@
     src=xos-setup-{{ xos_configuration }}-playbook.yml
     dest={{ ansible_user_dir }}/xos-setup-playbook.yml
 
+- name: Create template directory
+  file: path="{{ ansible_user_dir }}/templates" state=directory
+
+- name: Copy over necessary templates
+  copy:
+    src={{ item }}
+    dest={{ ansible_user_dir }}/templates/{{ item }}
+  with_items:
+    - docker.j2
+
 - name: Run the XOS ansible playbook
   command: ansible-playbook {{ ansible_user_dir }}/xos-setup-playbook.yml
   async: 4800
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 da40258..ed22592 100644
--- a/roles/xos-vm-install/templates/xos-setup-vars.yml.j2
+++ b/roles/xos-vm-install/templates/xos-setup-vars.yml.j2
@@ -18,3 +18,9 @@
 service_profile_repo_branch: "{{ service_profile_repo_branch }}"
 
 node_private_key: "{{ ansible_user_dir }}/node_key"
+
+docker_opts: "{{ docker_opts }}"
+docker_tag: "{{ docker_tag }}"
+docker_registry: "{{ docker_registry }}"
+
+local_docker_registry: "{{ local_docker_registry }}"