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.

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