2015-10-04 04:19:50 +08:00
---
2016-05-23 06:25:52 +08:00
- name : downloading...
debug :
msg : "{{ download.url }}"
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2016-05-23 06:25:52 +08:00
2015-12-31 23:05:25 +08:00
- name : Create dest directories
2016-05-23 06:25:52 +08:00
file : path={{local_release_dir}}/{{download.dest|dirname}} state=directory recurse=yes
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2015-12-31 23:05:25 +08:00
- name : Download items
get_url :
2016-05-23 06:25:52 +08:00
url : "{{download.url}}"
dest : "{{local_release_dir}}/{{download.dest}}"
sha256sum : "{{download.sha256 | default(omit)}}"
owner : "{{ download.owner|default(omit) }}"
mode : "{{ download.mode|default(omit) }}"
2016-09-14 20:30:57 +08:00
register : get_url_result
until : "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
retries : 4
2016-09-15 17:23:27 +08:00
delay : "{{ retry_stagger | random + 3 }}"
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2015-12-31 23:05:25 +08:00
- name : Extract archives
unarchive :
2016-05-23 06:25:52 +08:00
src : "{{ local_release_dir }}/{{download.dest}}"
dest : "{{ local_release_dir }}/{{download.dest|dirname}}"
owner : "{{ download.owner|default(omit) }}"
mode : "{{ download.mode|default(omit) }}"
2016-01-26 03:30:48 +08:00
copy : no
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and not download.container|bool and download.unarchive is defined and download.unarchive == True }}"
2016-01-26 03:30:48 +08:00
- name : Fix permissions
file :
state : file
2016-05-23 06:25:52 +08:00
path : "{{local_release_dir}}/{{download.dest}}"
owner : "{{ download.owner|default(omit) }}"
mode : "{{ download.mode|default(omit) }}"
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and not download.container|bool and (download.unarchive is not defined or download.unarchive == False) }}"
- name : pulling...
debug :
msg : "{{ download.repo }}:{{ download.tag }}"
when : "{{ download.enabled|bool and download.container|bool }}"
2016-09-15 00:20:10 +08:00
- name : Create dest directory for saved/loaded container images
2016-09-14 20:30:57 +08:00
file : path="{{local_release_dir}}/containers" state=directory recurse=yes
when : "{{ download.enabled|bool and download.container|bool }}"
#NOTE(bogdando) this brings no docker-py deps for nodes
- name : Download containers
command : "/usr/bin/docker pull {{ download.repo }}:{{ download.tag }}"
register : pull_task_result
until : pull_task_result.rc == 0
retries : 4
2016-09-15 17:23:27 +08:00
delay : "{{ retry_stagger | random + 3 }}"
2016-09-14 20:30:57 +08:00
when : "{{ download.enabled|bool and download.container|bool }}"
2016-09-27 17:10:13 +08:00
delegate_to : "{{ groups['kube-master'][0] if download_run_once|bool else inventory_hostname }}"
2016-05-18 12:30:01 +08:00
run_once : "{{ download_run_once|bool }}"
2016-09-15 00:20:10 +08:00
- set_fact :
fname : "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|regex_replace('/|\0|:', '_')}}.tar"
2016-10-24 21:11:52 +08:00
- name : "Set default value for 'container_changed' to false"
set_fact :
container_changed : false
- name : "Update the 'container_changed' fact"
set_fact :
container_changed : "{{ not 'up to date' in pull_task_result.stdout }}"
when : "{{ download.enabled|bool and download.container|bool }}"
delegate_to : "{{ groups['kube-master'][0] if download_run_once|bool else inventory_hostname }}"
run_once : "{{ download_run_once|bool }}"
2016-09-15 00:20:10 +08:00
- name : Download | save container images
shell : docker save "{{ download.repo }}:{{ download.tag }}" > "{{ fname }}"
delegate_to : "{{groups['kube-master'][0]}}"
run_once : true
2016-10-24 21:11:52 +08:00
when : ansible_os_family != "CoreOS" and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool
2016-09-15 00:20:10 +08:00
- name : Download | get container images
synchronize :
src : "{{ fname }}"
dest : "{{local_release_dir}}/containers"
mode : push
register : get_task
until : get_task|success
retries : 4
2016-09-15 17:23:27 +08:00
delay : "{{ retry_stagger | random + 3 }}"
2016-10-24 21:11:52 +08:00
when : ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool
2016-09-15 00:20:10 +08:00
- name : Download | load container images
shell : docker load < "{{ fname }}"
2016-10-24 21:11:52 +08:00
when : ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool