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.

191 lines
6.7 KiB

9 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. ---
  2. - name: gather os specific variables
  3. include_vars: "{{ item }}"
  4. with_first_found:
  5. - files:
  6. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_version|lower|replace('/', '_') }}.yml"
  7. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}-{{ host_architecture }}.yml"
  8. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_release|lower }}.yml"
  9. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  10. - "{{ ansible_distribution|lower }}-{{ host_architecture }}.yml"
  11. - "{{ ansible_distribution|lower }}.yml"
  12. - "{{ ansible_os_family|lower }}-{{ host_architecture }}.yml"
  13. - "{{ ansible_os_family|lower }}.yml"
  14. - defaults.yml
  15. paths:
  16. - ../vars
  17. skip: true
  18. tags:
  19. - facts
  20. # https://yum.dockerproject.org/repo/main/opensuse/ contains packages for an EOL
  21. # openSUSE version so we can't use it. The only alternative is to use the docker
  22. # packages from the distribution repositories.
  23. - name: Warn about Docker version on SUSE
  24. debug:
  25. msg: "SUSE distributions always install Docker from the distro repos"
  26. when: ansible_pkg_mgr == 'zypper'
  27. - include_tasks: set_facts_dns.yml
  28. when: dns_mode != 'none' and resolvconf_mode == 'docker_dns'
  29. tags:
  30. - facts
  31. - name: check for minimum kernel version
  32. fail:
  33. msg: >
  34. docker requires a minimum kernel version of
  35. {{ docker_kernel_min_version }} on
  36. {{ ansible_distribution }}-{{ ansible_distribution_version }}
  37. when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]) and (ansible_kernel|version_compare(docker_kernel_min_version, "<"))
  38. tags:
  39. - facts
  40. - import_tasks: pre-upgrade.yml
  41. - name: ensure docker-ce repository public key is installed
  42. action: "{{ docker_repo_key_info.pkg_key }}"
  43. args:
  44. id: "{{item}}"
  45. url: "{{docker_repo_key_info.url}}"
  46. state: present
  47. register: keyserver_task_result
  48. until: keyserver_task_result|succeeded
  49. retries: 4
  50. delay: "{{ retry_stagger | random + 3 }}"
  51. with_items: "{{ docker_repo_key_info.repo_keys }}"
  52. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic)
  53. - name: ensure docker-ce repository is enabled
  54. action: "{{ docker_repo_info.pkg_repo }}"
  55. args:
  56. repo: "{{item}}"
  57. state: present
  58. with_items: "{{ docker_repo_info.repos }}"
  59. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic) and (docker_repo_info.repos|length > 0)
  60. - name: ensure docker-engine repository public key is installed
  61. action: "{{ dockerproject_repo_key_info.pkg_key }}"
  62. args:
  63. id: "{{item}}"
  64. url: "{{dockerproject_repo_key_info.url}}"
  65. state: present
  66. register: keyserver_task_result
  67. until: keyserver_task_result|succeeded
  68. retries: 4
  69. delay: "{{ retry_stagger | random + 3 }}"
  70. with_items: "{{ dockerproject_repo_key_info.repo_keys }}"
  71. when:
  72. - not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic)
  73. - use_docker_engine is defined and use_docker_engine
  74. - name: ensure docker-engine repository is enabled
  75. action: "{{ dockerproject_repo_info.pkg_repo }}"
  76. args:
  77. repo: "{{item}}"
  78. state: present
  79. with_items: "{{ dockerproject_repo_info.repos }}"
  80. when:
  81. - use_docker_engine is defined and use_docker_engine
  82. - not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic) and (dockerproject_repo_info.repos|length > 0)
  83. - name: Configure docker repository on Fedora
  84. template:
  85. src: "fedora_docker.repo.j2"
  86. dest: "{{ yum_repo_dir }}/docker.repo"
  87. when: ansible_distribution == "Fedora" and not is_atomic
  88. - name: Configure docker repository on RedHat/CentOS
  89. template:
  90. src: "rh_docker.repo.j2"
  91. dest: "{{ yum_repo_dir }}/docker.repo"
  92. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  93. - name: Copy yum.conf for editing
  94. copy:
  95. src: "{{ yum_conf }}"
  96. dest: "{{ docker_yum_conf }}"
  97. remote_src: yes
  98. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  99. - name: Edit copy of yum.conf to set obsoletes=0
  100. lineinfile:
  101. path: "{{ docker_yum_conf }}"
  102. state: present
  103. regexp: '^obsoletes='
  104. line: 'obsoletes=0'
  105. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  106. - name: ensure docker packages are installed
  107. action: "{{ docker_package_info.pkg_mgr }}"
  108. args:
  109. pkg: "{{item.name}}"
  110. force: "{{item.force|default(omit)}}"
  111. conf_file: "{{item.yum_conf|default(omit)}}"
  112. state: present
  113. update_cache: "{{ omit if ansible_distribution == 'Fedora' else True }}"
  114. register: docker_task_result
  115. until: docker_task_result|succeeded
  116. retries: 4
  117. delay: "{{ retry_stagger | random + 3 }}"
  118. with_items: "{{ docker_package_info.pkgs }}"
  119. notify: restart docker
  120. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or is_atomic) and (docker_package_info.pkgs|length > 0)
  121. ignore_errors: true
  122. - name: get available packages on Ubuntu
  123. command: apt-cache policy docker-ce
  124. when:
  125. - docker_task_result|failed
  126. - ansible_distribution == 'Ubuntu'
  127. register: available_packages
  128. - name: show available packages on ubuntu
  129. fail:
  130. msg: "{{available_packages}}"
  131. when:
  132. - docker_task_result|failed
  133. - ansible_distribution == 'Ubuntu'
  134. # This is required to ensure any apt upgrade will not break kubernetes
  135. - name: Set docker pin priority to apt_preferences on Debian family
  136. template:
  137. src: "apt_preferences.d/debian_docker.j2"
  138. dest: "/etc/apt/preferences.d/docker"
  139. owner: "root"
  140. mode: 0644
  141. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic)
  142. - name: ensure service is started if docker packages are already present
  143. service:
  144. name: docker
  145. state: started
  146. when: docker_task_result is not changed
  147. - name: flush handlers so we can wait for docker to come up
  148. meta: flush_handlers
  149. - name: set fact for docker_version
  150. command: "docker version -f '{{ '{{' }}.Client.Version{{ '}}' }}'"
  151. register: installed_docker_version
  152. changed_when: false
  153. - name: check minimum docker version for docker_dns mode. You need at least docker version >= 1.12 for resolvconf_mode=docker_dns
  154. fail:
  155. msg: "You need at least docker version >= 1.12 for resolvconf_mode=docker_dns"
  156. when: >
  157. dns_mode != 'none' and
  158. resolvconf_mode == 'docker_dns' and
  159. installed_docker_version.stdout|version_compare('1.12', '<')
  160. - name: Set docker systemd config
  161. import_tasks: systemd.yml
  162. - name: ensure docker service is started and enabled
  163. service:
  164. name: "{{ item }}"
  165. enabled: yes
  166. state: started
  167. with_items:
  168. - docker