pull the xos-base container from the local registry

Change-Id: I358c0614b53385c4d9725e165a654d4e4a6f8898
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
 
 
+