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.

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