Skip to content
main.yml 6.54 KiB
Newer Older
Smaine Kahlouch's avatar
Smaine Kahlouch committed
---
- name: file_download | Create dest directories
  file:
    path: "{{local_release_dir}}/{{download.dest|dirname}}"
    state: directory
    recurse: yes
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - not download.container|bool
ant31's avatar
ant31 committed

- name: file_download | Download item
ant31's avatar
ant31 committed
  get_url:
    url: "{{download.url}}"
    dest: "{{local_release_dir}}/{{download.dest}}"
    sha256sum: "{{download.sha256 | default(omit)}}"
    owner: "{{ download.owner|default(omit) }}"
    mode: "{{ download.mode|default(omit) }}"
  register: get_url_result
  until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
  retries: 4
  delay: "{{ retry_stagger | random + 3 }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - not download.container|bool
ant31's avatar
ant31 committed

- name: file_download | Extract archives
ant31's avatar
ant31 committed
  unarchive:
    src: "{{ local_release_dir }}/{{download.dest}}"
    dest: "{{ local_release_dir }}/{{download.dest|dirname}}"
    owner: "{{ download.owner|default(omit) }}"
    mode: "{{ download.mode|default(omit) }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - not download.container|bool
    - download.unarchive|default(False)
- name: file_download | Fix permissions
    path: "{{local_release_dir}}/{{download.dest}}"
    owner: "{{ download.owner|default(omit) }}"
    mode: "{{ download.mode|default(omit) }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - not download.container|bool
    - (download.unarchive is not defined or download.unarchive == False)
    download_delegate: "{% if download_localhost|bool %}localhost{% else %}{{groups['kube-master'][0]}}{% endif %}"
  run_once: true
- name: container_download | Create dest directory for saved/loaded container images
  file:
    path: "{{local_release_dir}}/containers"
    state: directory
    recurse: yes
    mode: 0755
    owner: "{{ansible_ssh_user|default(ansible_user_id)}}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - download.container|bool
Bogdan Dobrelya's avatar
Bogdan Dobrelya committed
# This is required for the download_localhost delegate to work smooth with Container Linux by CoreOS cluster nodes
- name: container_download | Hack python binary path for localhost
  raw: sh -c "mkdir -p /opt/bin; ln -sf /usr/bin/python /opt/bin/python"
  delegate_to: localhost
  when: download_delegate == 'localhost'
  failed_when: false
- name: container_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
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download_run_once|bool
    - download.enabled|bool
    - download.container|bool
    - download_delegate == 'localhost'
- name: container_download | Make download decision if pull is required by tag or sha256
  include: set_docker_image_facts.yml
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - download.container|bool
  delegate_to: "{{ download_delegate if download_run_once|bool or omit }}"
  run_once: "{{ download_run_once|bool }}"
- name: container_download | Download containers if pull is required or told to always pull
  command: "{{ docker_bin_dir }}/docker pull {{ pull_args }}"
  register: pull_task_result
  until: pull_task_result|succeeded
  retries: 4
  delay: "{{ retry_stagger | random + 3 }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - download.container|bool
    - pull_required|bool|default(download_always_pull)
  delegate_to: "{{ download_delegate if download_run_once|bool or omit }}"
  run_once: "{{ download_run_once|bool }}"
    fname: "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|default(download.sha256)|regex_replace('/|\0|:', '_')}}.tar"
  run_once: true
- name: "container_download | Set default value for 'container_changed' to false"
    container_changed: "{{pull_required|default(false)|bool}}"
- name: "container_download | Update the 'container_changed' fact"
    container_changed: "{{ pull_required|bool|default(false) or not 'up to date' in pull_task_result.stdout }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - download.container|bool
    - pull_required|bool|default(download_always_pull)
  run_once: "{{ download_run_once|bool }}"
- name: container_download | Stat saved container image
  register: img
  changed_when: false
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  when:
    - download.enabled|bool
    - download.container|bool
    - download_run_once|bool
  delegate_to: "{{ download_delegate }}"
  become: false
  run_once: true
- name: container_download | save container images
  shell: "{{ docker_bin_dir }}/docker save {{ pull_args }} | gzip -{{ download_compress }} > {{ fname }}"
  delegate_to: "{{ download_delegate }}"
  register: saved
  run_once: true
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  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)
- name: container_download | copy container images to ansible host
  synchronize:
    src: "{{ fname }}"
    dest: "{{ fname }}"
    mode: pull
  delegate_to: localhost
  become: false
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  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
- name: container_download | upload container images to nodes
  synchronize:
    src: "{{ fname }}"
    dest: "{{ fname }}"
    mode: push
  delegate_to: localhost
  become: false
  register: get_task
  retries: 4
  delay: "{{ retry_stagger | random + 3 }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  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
- name: container_download | load container images
  shell: "{{ docker_bin_dir }}/docker load < {{ fname }}"
Sergii Golovatiuk's avatar
Sergii Golovatiuk committed
  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