2015-10-03 20:19:50 +00:00
---
2016-05-22 22:25:52 +00:00
- name : downloading...
debug :
msg : "{{ download.url }}"
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2016-05-22 22:25:52 +00:00
2015-12-31 15:05:25 +00:00
- name : Create dest directories
2016-05-22 22:25:52 +00:00
file : path={{local_release_dir}}/{{download.dest|dirname}} state=directory recurse=yes
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2016-12-09 15:57:56 +00:00
tags : bootstrap-os
2015-12-31 15:05:25 +00:00
- name : Download items
get_url :
2016-05-22 22:25:52 +00: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 12:30:57 +00: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 09:23:27 +00:00
delay : "{{ retry_stagger | random + 3 }}"
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and not download.container|bool }}"
2015-12-31 15:05:25 +00:00
- name : Extract archives
unarchive :
2016-05-22 22:25:52 +00: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-25 19:30:48 +00:00
copy : no
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and not download.container|bool and download.unarchive is defined and download.unarchive == True }}"
2016-01-25 19:30:48 +00:00
- name : Fix permissions
file :
state : file
2016-05-22 22:25:52 +00:00
path : "{{local_release_dir}}/{{download.dest}}"
owner : "{{ download.owner|default(omit) }}"
mode : "{{ download.mode|default(omit) }}"
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and not download.container|bool and (download.unarchive is not defined or download.unarchive == False) }}"
2016-11-18 12:29:03 +00:00
- set_fact :
download_delegate : "{% if download_localhost %}localhost{% else %}{{groups['kube-master'][0]}}{% endif %}"
2016-12-08 13:36:00 +00:00
tags : facts
2016-11-18 12:29:03 +00:00
2016-09-14 16:20:10 +00:00
- name : Create dest directory for saved/loaded container images
2016-11-22 16:58:46 +00:00
file : path="{{local_release_dir}}/containers" state=directory recurse=yes mode=0755 owner={{ansible_ssh_user|default(ansible_user_id)}}
2016-09-14 12:30:57 +00:00
when : "{{ download.enabled|bool and download.container|bool }}"
2016-12-09 15:57:56 +00:00
tags : bootstrap-os
2016-09-14 12:30:57 +00:00
2017-01-05 10:35:16 +00:00
# This is required for the download_localhost delegate to work smooth with Container Linux by CoreOS cluster nodes
2016-11-18 12:29:03 +00:00
- name : Hack python binary path for localhost
raw : sh -c "mkdir -p /opt/bin; ln -sf /usr/bin/python /opt/bin/python"
when : "{{ download_delegate == 'localhost' }}"
delegate_to : localhost
2016-12-27 11:38:54 +00:00
failed_when : false
2016-11-18 12:29:03 +00:00
run_once : true
2016-12-09 15:57:56 +00:00
tags : localhost
2016-11-18 12:29:03 +00:00
- name : Download | create local directory for saved/loaded container images
file : path="{{local_release_dir}}/containers" state=directory recurse=yes
delegate_to : localhost
become : false
run_once : true
when : "{{ download_run_once|bool and download.enabled|bool and download.container|bool and download_delegate == 'localhost' }}"
2016-12-09 15:57:56 +00:00
tags : localhost
2016-11-18 12:29:03 +00:00
2016-12-19 14:50:04 +00:00
- name : Make download decision if pull is required by tag or sha256
include : set_docker_image_facts.yml
when : "{{ download.enabled|bool and download.container|bool }}"
delegate_to : "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
run_once : "{{ download_run_once|bool }}"
tags : facts
- name : pulling...
debug :
msg : "{{ pull_args }}"
when : "{{ download.enabled|bool and download.container|bool }}"
2016-09-14 12:30:57 +00:00
#NOTE(bogdando) this brings no docker-py deps for nodes
2016-12-19 14:50:04 +00:00
- name : Download containers if pull is required or told to always pull
2016-12-23 14:44:44 +00:00
command : "{{ docker_bin_dir }}/docker pull {{ pull_args }}"
2016-09-14 12:30:57 +00:00
register : pull_task_result
2016-11-18 12:29:03 +00:00
until : pull_task_result|success
2016-09-14 12:30:57 +00:00
retries : 4
2016-09-15 09:23:27 +00:00
delay : "{{ retry_stagger | random + 3 }}"
2016-12-19 14:50:04 +00:00
when : "{{ download.enabled|bool and download.container|bool and pull_required|bool|default(download_always_pull) }}"
2016-11-18 12:29:03 +00:00
delegate_to : "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
2016-05-18 04:30:01 +00:00
run_once : "{{ download_run_once|bool }}"
2016-09-14 16:20:10 +00:00
- set_fact :
2016-12-19 14:50:04 +00:00
fname : "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|default(download.sha256)|regex_replace('/|\0|:', '_')}}.tar"
2016-12-08 13:36:00 +00:00
tags : facts
2016-09-14 16:20:10 +00:00
2016-10-24 13:11:52 +00:00
- name : "Set default value for 'container_changed' to false"
set_fact :
2016-12-19 14:50:04 +00:00
container_changed : "{{pull_required|bool|default(false)}}"
2016-10-24 13:11:52 +00:00
- name : "Update the 'container_changed' fact"
set_fact :
2016-12-19 14:50:04 +00:00
container_changed : "{{ pull_required|bool|default(false) or not 'up to date' in pull_task_result.stdout }}"
when : "{{ download.enabled|bool and download.container|bool and pull_required|bool|default(download_always_pull) }}"
2016-11-18 12:29:03 +00:00
delegate_to : "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
2016-10-24 13:11:52 +00:00
run_once : "{{ download_run_once|bool }}"
2016-12-08 13:36:00 +00:00
tags : facts
2016-10-24 13:11:52 +00:00
2016-11-18 12:29:03 +00:00
- name : Stat saved container image
stat : path="{{fname}}"
register : img
changed_when : false
when : "{{ download.enabled|bool and download.container|bool and download_run_once|bool }}"
delegate_to : "{{ download_delegate }}"
become : false
2016-09-14 16:20:10 +00:00
run_once : true
2016-12-09 15:57:56 +00:00
tags : facts
2016-09-14 16:20:10 +00:00
2016-11-18 12:29:03 +00:00
- name : Download | save container images
2016-12-23 14:44:44 +00:00
shell : "{{ docker_bin_dir }}/docker save {{ pull_args }} | gzip -{{ download_compress }} > {{ fname }}"
2016-11-18 12:29:03 +00:00
delegate_to : "{{ download_delegate }}"
register : saved
2016-11-16 10:59:39 +00:00
run_once : true
2017-01-05 15:32:08 +00:00
when : (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool and (container_changed|bool or not img.stat.exists)
2016-11-16 10:59:39 +00:00
- name : Download | copy container images to ansible host
synchronize :
src : "{{ fname }}"
dest : "{{ fname }}"
mode : pull
delegate_to : localhost
become : false
2017-01-05 15:32:08 +00:00
when : not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname == groups['kube-master'][0] and download_delegate != "localhost" and download_run_once|bool and download.enabled|bool and download.container|bool and saved.changed
2016-11-16 10:59:39 +00:00
- name : Download | upload container images to nodes
2016-09-14 16:20:10 +00:00
synchronize :
src : "{{ fname }}"
2016-11-16 10:59:39 +00:00
dest : "{{ fname }}"
2016-09-14 16:20:10 +00:00
mode : push
2016-11-16 10:59:39 +00:00
delegate_to : localhost
become : false
2016-09-14 16:20:10 +00:00
register : get_task
until : get_task|success
retries : 4
2016-09-15 09:23:27 +00:00
delay : "{{ retry_stagger | random + 3 }}"
2017-01-05 15:32:08 +00:00
when : (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool
2016-12-09 15:57:56 +00:00
tags : [ upload, upgrade]
2016-09-14 16:20:10 +00:00
- name : Download | load container images
2016-12-23 14:44:44 +00:00
shell : "{{ docker_bin_dir }}/docker load < {{ fname }}"
2017-01-05 15:32:08 +00:00
when : (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] and inventory_hostname != groups['kube-master'][0] or download_delegate == "localhost") and download_run_once|bool and download.enabled|bool and download.container|bool
2016-12-09 15:57:56 +00:00
tags : [ upload, upgrade]