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.

162 lines
6.5 KiB

9 years ago
  1. ---
  2. - name: downloading...
  3. debug:
  4. msg: "{{ download.url }}"
  5. when: "{{ download.enabled|bool and not download.container|bool }}"
  6. - name: Create dest directories
  7. file:
  8. path: "{{local_release_dir}}/{{download.dest|dirname}}"
  9. state: directory
  10. recurse: yes
  11. when: "{{ download.enabled|bool and not download.container|bool }}"
  12. tags: bootstrap-os
  13. - name: Download items
  14. get_url:
  15. url: "{{download.url}}"
  16. dest: "{{local_release_dir}}/{{download.dest}}"
  17. sha256sum: "{{download.sha256 | default(omit)}}"
  18. owner: "{{ download.owner|default(omit) }}"
  19. mode: "{{ download.mode|default(omit) }}"
  20. register: get_url_result
  21. until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
  22. retries: 4
  23. delay: "{{ retry_stagger | random + 3 }}"
  24. when: "{{ download.enabled|bool and not download.container|bool }}"
  25. - name: Extract archives
  26. unarchive:
  27. src: "{{ local_release_dir }}/{{download.dest}}"
  28. dest: "{{ local_release_dir }}/{{download.dest|dirname}}"
  29. owner: "{{ download.owner|default(omit) }}"
  30. mode: "{{ download.mode|default(omit) }}"
  31. copy: no
  32. when: "{{ download.enabled|bool and not download.container|bool and download.unarchive is defined and download.unarchive == True }}"
  33. - name: Fix permissions
  34. file:
  35. state: file
  36. path: "{{local_release_dir}}/{{download.dest}}"
  37. owner: "{{ download.owner|default(omit) }}"
  38. mode: "{{ download.mode|default(omit) }}"
  39. when: "{{ download.enabled|bool and not download.container|bool and (download.unarchive is not defined or download.unarchive == False) }}"
  40. - set_fact:
  41. download_delegate: "{% if download_localhost %}localhost{% else %}{{groups['kube-master'][0]}}{% endif %}"
  42. tags: facts
  43. - name: Create dest directory for saved/loaded container images
  44. file:
  45. path: "{{local_release_dir}}/containers"
  46. state: directory
  47. recurse: yes
  48. mode: 0755
  49. owner: "{{ansible_ssh_user|default(ansible_user_id)}}"
  50. when: "{{ download.enabled|bool and download.container|bool }}"
  51. tags: bootstrap-os
  52. # This is required for the download_localhost delegate to work smooth with Container Linux by CoreOS cluster nodes
  53. - name: Hack python binary path for localhost
  54. raw: sh -c "mkdir -p /opt/bin; ln -sf /usr/bin/python /opt/bin/python"
  55. when: "{{ download_delegate == 'localhost' }}"
  56. delegate_to: localhost
  57. failed_when: false
  58. run_once: true
  59. tags: localhost
  60. - name: Download | create local directory for saved/loaded container images
  61. file:
  62. path: "{{local_release_dir}}/containers"
  63. state: directory
  64. recurse: yes
  65. delegate_to: localhost
  66. become: false
  67. run_once: true
  68. when: "{{ download_run_once|bool and download.enabled|bool and download.container|bool and download_delegate == 'localhost' }}"
  69. tags: localhost
  70. - name: Make download decision if pull is required by tag or sha256
  71. include: set_docker_image_facts.yml
  72. when: "{{ download.enabled|bool and download.container|bool }}"
  73. delegate_to: "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
  74. run_once: "{{ download_run_once|bool }}"
  75. tags: facts
  76. - name: pulling...
  77. debug:
  78. msg: "{{ pull_args }}"
  79. when: "{{ download.enabled|bool and download.container|bool }}"
  80. #NOTE(bogdando) this brings no docker-py deps for nodes
  81. - name: Download containers if pull is required or told to always pull
  82. command: "{{ docker_bin_dir }}/docker pull {{ pull_args }}"
  83. register: pull_task_result
  84. until: pull_task_result|success
  85. retries: 4
  86. delay: "{{ retry_stagger | random + 3 }}"
  87. when: "{{ download.enabled|bool and download.container|bool and pull_required|bool|default(download_always_pull) }}"
  88. delegate_to: "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
  89. run_once: "{{ download_run_once|bool }}"
  90. - set_fact:
  91. fname: "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|default(download.sha256)|regex_replace('/|\0|:', '_')}}.tar"
  92. tags: facts
  93. - name: "Set default value for 'container_changed' to false"
  94. set_fact:
  95. container_changed: "{{pull_required|default(false)|bool}}"
  96. - name: "Update the 'container_changed' fact"
  97. set_fact:
  98. container_changed: "{{ pull_required|bool|default(false) or not 'up to date' in pull_task_result.stdout }}"
  99. when: "{{ download.enabled|bool and download.container|bool and pull_required|bool|default(download_always_pull) }}"
  100. delegate_to: "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
  101. run_once: "{{ download_run_once|bool }}"
  102. tags: facts
  103. - name: Stat saved container image
  104. stat:
  105. path: "{{fname}}"
  106. register: img
  107. changed_when: false
  108. when: "{{ download.enabled|bool and download.container|bool and download_run_once|bool }}"
  109. delegate_to: "{{ download_delegate }}"
  110. become: false
  111. run_once: true
  112. tags: facts
  113. - name: Download | save container images
  114. shell: "{{ docker_bin_dir }}/docker save {{ pull_args }} | gzip -{{ download_compress }} > {{ fname }}"
  115. delegate_to: "{{ download_delegate }}"
  116. register: saved
  117. run_once: true
  118. 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)
  119. - name: Download | copy container images to ansible host
  120. synchronize:
  121. src: "{{ fname }}"
  122. dest: "{{ fname }}"
  123. mode: pull
  124. delegate_to: localhost
  125. become: false
  126. 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
  127. - name: Download | upload container images to nodes
  128. synchronize:
  129. src: "{{ fname }}"
  130. dest: "{{ fname }}"
  131. mode: push
  132. delegate_to: localhost
  133. become: false
  134. register: get_task
  135. until: get_task|success
  136. retries: 4
  137. delay: "{{ retry_stagger | random + 3 }}"
  138. 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
  139. tags: [upload, upgrade]
  140. - name: Download | load container images
  141. shell: "{{ docker_bin_dir }}/docker load < {{ fname }}"
  142. 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
  143. tags: [upload, upgrade]