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.

143 lines
5.8 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. - name: pulling...
  38. debug:
  39. msg: "{{ download.repo }}:{{ download.tag }}"
  40. when: "{{ download.enabled|bool and download.container|bool }}"
  41. - set_fact:
  42. download_delegate: "{% if download_localhost %}localhost{% else %}{{groups['kube-master'][0]}}{% endif %}"
  43. tags: facts
  44. - name: Create dest directory for saved/loaded container images
  45. file: path="{{local_release_dir}}/containers" state=directory recurse=yes mode=0755 owner={{ansible_ssh_user|default(ansible_user_id)}}
  46. when: "{{ download.enabled|bool and download.container|bool }}"
  47. tags: bootstrap-os
  48. # This is required for the download_localhost delegate to work smooth with CoreOS cluster nodes
  49. - name: Hack python binary path for localhost
  50. raw: sh -c "mkdir -p /opt/bin; ln -sf /usr/bin/python /opt/bin/python"
  51. when: "{{ download_delegate == 'localhost' }}"
  52. delegate_to: localhost
  53. ignore_errors: true
  54. run_once: true
  55. tags: localhost
  56. - name: Download | create local directory for saved/loaded container images
  57. file: path="{{local_release_dir}}/containers" state=directory recurse=yes
  58. delegate_to: localhost
  59. become: false
  60. run_once: true
  61. when: "{{ download_run_once|bool and download.enabled|bool and download.container|bool and download_delegate == 'localhost' }}"
  62. tags: localhost
  63. #NOTE(bogdando) this brings no docker-py deps for nodes
  64. - name: Download containers
  65. command: "/usr/bin/docker pull {{ download.repo }}:{{ download.tag }}"
  66. register: pull_task_result
  67. until: pull_task_result|success
  68. retries: 4
  69. delay: "{{ retry_stagger | random + 3 }}"
  70. when: "{{ download.enabled|bool and download.container|bool }}"
  71. delegate_to: "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
  72. run_once: "{{ download_run_once|bool }}"
  73. - set_fact:
  74. fname: "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|regex_replace('/|\0|:', '_')}}.tar"
  75. tags: facts
  76. - name: "Set default value for 'container_changed' to false"
  77. set_fact:
  78. container_changed: false
  79. - name: "Update the 'container_changed' fact"
  80. set_fact:
  81. container_changed: "{{ not 'up to date' in pull_task_result.stdout }}"
  82. when: "{{ download.enabled|bool and download.container|bool }}"
  83. delegate_to: "{{ download_delegate if download_run_once|bool else inventory_hostname }}"
  84. run_once: "{{ download_run_once|bool }}"
  85. tags: facts
  86. - name: Stat saved container image
  87. stat: path="{{fname}}"
  88. register: img
  89. changed_when: false
  90. when: "{{ download.enabled|bool and download.container|bool and download_run_once|bool }}"
  91. delegate_to: "{{ download_delegate }}"
  92. become: false
  93. run_once: true
  94. tags: facts
  95. - name: Download | save container images
  96. shell: docker save "{{ download.repo }}:{{ download.tag }}" | gzip -{{ download_compress }} > "{{ fname }}"
  97. delegate_to: "{{ download_delegate }}"
  98. register: saved
  99. run_once: true
  100. when: (ansible_os_family != "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)
  101. - name: Download | copy container images to ansible host
  102. synchronize:
  103. src: "{{ fname }}"
  104. dest: "{{ fname }}"
  105. mode: pull
  106. delegate_to: localhost
  107. become: false
  108. when: ansible_os_family != "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
  109. - name: Download | upload container images to nodes
  110. synchronize:
  111. src: "{{ fname }}"
  112. dest: "{{ fname }}"
  113. mode: push
  114. delegate_to: localhost
  115. become: false
  116. register: get_task
  117. until: get_task|success
  118. retries: 4
  119. delay: "{{ retry_stagger | random + 3 }}"
  120. when: (ansible_os_family != "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
  121. tags: [upload, upgrade]
  122. - name: Download | load container images
  123. shell: docker load < "{{ fname }}"
  124. when: (ansible_os_family != "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
  125. tags: [upload, upgrade]