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