From 9926395e5b4f3f35d00b33fd7a4d130977f70df7 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Wed, 14 Sep 2016 18:20:10 +0200 Subject: [PATCH] Distribute downloaded artifacts Signed-off-by: Bogdan Dobrelya --- roles/download/tasks/main.yml | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/roles/download/tasks/main.yml b/roles/download/tasks/main.yml index 8d9c351a3..73622f06d 100644 --- a/roles/download/tasks/main.yml +++ b/roles/download/tasks/main.yml @@ -9,6 +9,7 @@ - name: Create dest directories file: path={{local_release_dir}}/{{download.dest|dirname}} state=directory recurse=yes when: "{{ download.enabled|bool and not download.container|bool }}" + delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else omit }}" run_once: "{{ download_run_once|bool }}" - name: Download items @@ -23,6 +24,7 @@ retries: 4 delay: "{{ 20 | random + 3 }}" when: "{{ download.enabled|bool and not download.container|bool }}" + delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else omit }}" run_once: "{{ download_run_once|bool }}" - name: Extract archives @@ -33,6 +35,7 @@ mode: "{{ download.mode|default(omit) }}" copy: no when: "{{ download.enabled|bool and not download.container|bool and download.unarchive is defined and download.unarchive == True }}" + delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else omit }}" run_once: "{{ download_run_once|bool }}" - name: Fix permissions @@ -42,6 +45,7 @@ owner: "{{ download.owner|default(omit) }}" mode: "{{ download.mode|default(omit) }}" when: "{{ download.enabled|bool and not download.container|bool and (download.unarchive is not defined or download.unarchive == False) }}" + delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else omit }}" run_once: "{{ download_run_once|bool }}" - name: pulling... @@ -49,10 +53,9 @@ msg: "{{ download.repo }}:{{ download.tag }}" when: "{{ download.enabled|bool and download.container|bool }}" -- name: Create dest directory for container images to be saved +- name: Create dest directory for saved/loaded container images file: path="{{local_release_dir}}/containers" state=directory recurse=yes when: "{{ download.enabled|bool and download.container|bool }}" - run_once: "{{ download_run_once|bool }}" #NOTE(bogdando) this brings no docker-py deps for nodes - name: Download containers @@ -62,4 +65,29 @@ retries: 4 delay: "{{ 20 | random + 3 }}" when: "{{ download.enabled|bool and download.container|bool }}" + delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else omit }}" run_once: "{{ download_run_once|bool }}" + +- set_fact: + fname: "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|regex_replace('/|\0|:', '_')}}.tar" + +- name: Download | save container images + shell: docker save "{{ download.repo }}:{{ download.tag }}" > "{{ fname }}" + delegate_to: "{{groups['kube-master'][0]}}" + run_once: true + when: ansible_os_family != "CoreOS" and download_run_once|bool + +- name: Download | get container images + synchronize: + src: "{{ fname }}" + dest: "{{local_release_dir}}/containers" + mode: push + register: get_task + until: get_task|success + retries: 4 + delay: "{{ 20 | random + 3 }}" + when: ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool + +- name: Download | load container images + shell: docker load < "{{ fname }}" + when: ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool