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.

217 lines
6.6 KiB

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