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.

94 lines
3.9 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. - name: Download items
  10. get_url:
  11. url: "{{download.url}}"
  12. dest: "{{local_release_dir}}/{{download.dest}}"
  13. sha256sum: "{{download.sha256 | default(omit)}}"
  14. owner: "{{ download.owner|default(omit) }}"
  15. mode: "{{ download.mode|default(omit) }}"
  16. register: get_url_result
  17. until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg"
  18. retries: 4
  19. delay: "{{ retry_stagger | random + 3 }}"
  20. when: "{{ download.enabled|bool and not download.container|bool }}"
  21. - name: Extract archives
  22. unarchive:
  23. src: "{{ local_release_dir }}/{{download.dest}}"
  24. dest: "{{ local_release_dir }}/{{download.dest|dirname}}"
  25. owner: "{{ download.owner|default(omit) }}"
  26. mode: "{{ download.mode|default(omit) }}"
  27. copy: no
  28. when: "{{ download.enabled|bool and not download.container|bool and download.unarchive is defined and download.unarchive == True }}"
  29. - name: Fix permissions
  30. file:
  31. state: file
  32. path: "{{local_release_dir}}/{{download.dest}}"
  33. owner: "{{ download.owner|default(omit) }}"
  34. mode: "{{ download.mode|default(omit) }}"
  35. when: "{{ download.enabled|bool and not download.container|bool and (download.unarchive is not defined or download.unarchive == False) }}"
  36. - name: pulling...
  37. debug:
  38. msg: "{{ download.repo }}:{{ download.tag }}"
  39. when: "{{ download.enabled|bool and download.container|bool }}"
  40. - name: Create dest directory for saved/loaded container images
  41. file: path="{{local_release_dir}}/containers" state=directory recurse=yes
  42. when: "{{ download.enabled|bool and download.container|bool }}"
  43. #NOTE(bogdando) this brings no docker-py deps for nodes
  44. - name: Download containers
  45. command: "/usr/bin/docker pull {{ download.repo }}:{{ download.tag }}"
  46. register: pull_task_result
  47. until: pull_task_result.rc == 0
  48. retries: 4
  49. delay: "{{ retry_stagger | random + 3 }}"
  50. when: "{{ download.enabled|bool and download.container|bool }}"
  51. delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else inventory_hostname }}"
  52. run_once: "{{ download_run_once|bool }}"
  53. - set_fact:
  54. fname: "{{local_release_dir}}/containers/{{download.repo|regex_replace('/|\0|:', '_')}}:{{download.tag|regex_replace('/|\0|:', '_')}}.tar"
  55. - name: "Set default value for 'container_changed' to false"
  56. set_fact:
  57. container_changed: false
  58. - name: "Update the 'container_changed' fact"
  59. set_fact:
  60. container_changed: "{{ not 'up to date' in pull_task_result.stdout }}"
  61. when: "{{ download.enabled|bool and download.container|bool }}"
  62. delegate_to: "{{ groups['kube-master'][0] if download_run_once|bool else inventory_hostname }}"
  63. run_once: "{{ download_run_once|bool }}"
  64. - name: Download | save container images
  65. shell: docker save "{{ download.repo }}:{{ download.tag }}" > "{{ fname }}"
  66. delegate_to: "{{groups['kube-master'][0]}}"
  67. run_once: true
  68. when: ansible_os_family != "CoreOS" and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool
  69. - name: Download | get container images
  70. synchronize:
  71. src: "{{ fname }}"
  72. dest: "{{local_release_dir}}/containers"
  73. mode: push
  74. register: get_task
  75. until: get_task|success
  76. retries: 4
  77. delay: "{{ retry_stagger | random + 3 }}"
  78. when: ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool
  79. - name: Download | load container images
  80. shell: docker load < "{{ fname }}"
  81. when: ansible_os_family != "CoreOS" and inventory_hostname != groups['kube-master'][0] and download_run_once|bool and download.enabled|bool and download.container|bool and container_changed|bool