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.

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