You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.2 KiB

  1. ---
  2. - name: container_download | Make download decision if pull is required by tag or sha256
  3. include: set_docker_image_facts.yml
  4. when:
  5. - download.enabled
  6. - download.container
  7. tags:
  8. - facts
  9. - name: container_download | Set file name of container tarballs
  10. set_fact:
  11. fname: "{{ local_release_dir }}/containers/{{ download.repo|regex_replace('/|\0|:', '_') }}:{{ download.tag|default(download.sha256)|regex_replace('/|\0|:', '_') }}.tar"
  12. run_once: true
  13. when:
  14. - download.enabled
  15. - download.container
  16. - download_run_once
  17. tags:
  18. - facts
  19. - name: "container_download | Set default value for 'container_changed' to false"
  20. set_fact:
  21. container_changed: "{{ pull_required|default(false) }}"
  22. when:
  23. - download.enabled
  24. - download.container
  25. - download_run_once
  26. - name: "container_download | Update the 'container_changed' fact"
  27. set_fact:
  28. container_changed: "{{ pull_required|default(false) or not 'up to date' in pull_task_result.stdout }}"
  29. when:
  30. - download.enabled
  31. - download.container
  32. - download_run_once
  33. - pull_required|default(download_always_pull)
  34. run_once: "{{ download_run_once }}"
  35. tags:
  36. - facts
  37. - name: container_download | Stat saved container image
  38. stat:
  39. path: "{{ fname }}"
  40. register: img
  41. changed_when: false
  42. delegate_to: "{{ download_delegate }}"
  43. delegate_facts: no
  44. become: false
  45. run_once: true
  46. when:
  47. - download.enabled
  48. - download.container
  49. - download_run_once
  50. - any_pull_required | default(download_always_pull)
  51. tags:
  52. - facts
  53. - name: container_download | save container images
  54. shell: "{{ docker_bin_dir }}/docker save {{ pull_args }} | gzip -{{ download_compress }} > {{ fname }}"
  55. delegate_to: "{{ download_delegate }}"
  56. delegate_facts: no
  57. register: saved
  58. failed_when: saved.stderr
  59. when:
  60. - download.enabled
  61. - download.container
  62. - download_run_once
  63. - any_pull_required | default(download_always_pull)
  64. - (ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] or download_delegate == "localhost")
  65. - (container_changed or not img.stat.exists)
  66. - name: container_download | create container images directory on ansible host
  67. file:
  68. state: directory
  69. path: "{{ fname | dirname }}"
  70. delegate_to: localhost
  71. delegate_facts: no
  72. run_once: true
  73. become: false
  74. when:
  75. - download.enabled
  76. - download.container
  77. - download_run_once
  78. - any_pull_required | default(download_always_pull)
  79. - ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"]
  80. - inventory_hostname == download_delegate
  81. - download_delegate != "localhost"
  82. - saved.changed
  83. - name: container_download | copy container images to ansible host
  84. synchronize:
  85. src: "{{ fname }}"
  86. dest: "{{ fname }}"
  87. use_ssh_args: "{{ has_bastion | default(false) }}"
  88. mode: pull
  89. private_key: "{{ ansible_ssh_private_key_file }}"
  90. become: false
  91. when:
  92. - download.enabled
  93. - download.container
  94. - download_run_once
  95. - ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"]
  96. - inventory_hostname == download_delegate
  97. - download_delegate != "localhost"
  98. - saved.changed
  99. - name: container_download | upload container images to nodes
  100. synchronize:
  101. src: "{{ fname }}"
  102. dest: "{{ fname }}"
  103. use_ssh_args: "{{ has_bastion | default(false) }}"
  104. mode: push
  105. become: true
  106. register: get_task
  107. until: get_task is succeeded
  108. retries: 4
  109. delay: "{{ retry_stagger | random + 3 }}"
  110. when:
  111. - download.enabled
  112. - download.container
  113. - download_run_once
  114. - pull_required|default(download_always_pull)
  115. - (ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] and
  116. inventory_hostname != download_delegate or
  117. download_delegate == "localhost")
  118. tags:
  119. - upload
  120. - upgrade
  121. - name: container_download | load container images
  122. shell: "{{ docker_bin_dir }}/docker load < {{ fname }}"
  123. when:
  124. - download.enabled
  125. - download.container
  126. - download_run_once
  127. - pull_required|default(download_always_pull)
  128. - (ansible_os_family not in ["CoreOS", "Container Linux by CoreOS"] and
  129. inventory_hostname != download_delegate or download_delegate == "localhost")
  130. tags:
  131. - upload
  132. - upgrade