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.

152 lines
5.3 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 }}.yml"
  8. - "{{ ansible_distribution|lower }}-{{ ansible_distribution_major_version|lower|replace('/', '_') }}.yml"
  9. - "{{ ansible_distribution|lower }}.yml"
  10. - "{{ ansible_os_family|lower }}.yml"
  11. - defaults.yml
  12. paths:
  13. - ../vars
  14. skip: true
  15. tags:
  16. - facts
  17. # https://yum.dockerproject.org/repo/main/opensuse/ contains packages for an EOL
  18. # openSUSE version so we can't use it. The only alternative is to use the docker
  19. # packages from the distribution repositories.
  20. - name: Warn about Docker version on SUSE
  21. debug:
  22. msg: "SUSE distributions always install Docker from the distro repos"
  23. when: ansible_pkg_mgr == 'zypper'
  24. - include_tasks: set_facts_dns.yml
  25. when: dns_mode != 'none' and resolvconf_mode == 'docker_dns'
  26. tags:
  27. - facts
  28. - name: check for minimum kernel version
  29. fail:
  30. msg: >
  31. docker requires a minimum kernel version of
  32. {{ docker_kernel_min_version }} on
  33. {{ ansible_distribution }}-{{ ansible_distribution_version }}
  34. when: (not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]) and (ansible_kernel|version_compare(docker_kernel_min_version, "<"))
  35. tags:
  36. - facts
  37. - import_tasks: pre-upgrade.yml
  38. - name: ensure docker-ce repository public key is installed
  39. action: "{{ docker_repo_key_info.pkg_key }}"
  40. args:
  41. id: "{{item}}"
  42. url: "{{docker_repo_key_info.url}}"
  43. state: present
  44. register: keyserver_task_result
  45. until: keyserver_task_result|succeeded
  46. retries: 4
  47. delay: "{{ retry_stagger | random + 3 }}"
  48. with_items: "{{ docker_repo_key_info.repo_keys }}"
  49. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic)
  50. - name: ensure docker-ce repository is enabled
  51. action: "{{ docker_repo_info.pkg_repo }}"
  52. args:
  53. repo: "{{item}}"
  54. state: present
  55. with_items: "{{ docker_repo_info.repos }}"
  56. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic) and (docker_repo_info.repos|length > 0)
  57. - name: ensure docker-engine repository public key is installed
  58. action: "{{ dockerproject_repo_key_info.pkg_key }}"
  59. args:
  60. id: "{{item}}"
  61. url: "{{dockerproject_repo_key_info.url}}"
  62. state: present
  63. register: keyserver_task_result
  64. until: keyserver_task_result|succeeded
  65. retries: 4
  66. delay: "{{ retry_stagger | random + 3 }}"
  67. with_items: "{{ dockerproject_repo_key_info.repo_keys }}"
  68. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic)
  69. - name: ensure docker-engine repository is enabled
  70. action: "{{ dockerproject_repo_info.pkg_repo }}"
  71. args:
  72. repo: "{{item}}"
  73. state: present
  74. with_items: "{{ dockerproject_repo_info.repos }}"
  75. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS", "RedHat", "Suse"] or is_atomic) and (dockerproject_repo_info.repos|length > 0)
  76. - name: Configure docker repository on RedHat/CentOS
  77. template:
  78. src: "rh_docker.repo.j2"
  79. dest: "/etc/yum.repos.d/docker.repo"
  80. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  81. - name: Copy yum.conf for editing
  82. copy:
  83. src: "{{ yum_conf }}"
  84. dest: "{{ docker_yum_conf }}"
  85. remote_src: yes
  86. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  87. - name: Edit copy of yum.conf to set obsoletes=0
  88. lineinfile:
  89. path: "{{ docker_yum_conf }}"
  90. state: present
  91. regexp: '^obsoletes='
  92. line: 'obsoletes=0'
  93. when: ansible_distribution in ["CentOS","RedHat"] and not is_atomic
  94. - name: ensure docker packages are installed
  95. action: "{{ docker_package_info.pkg_mgr }}"
  96. args:
  97. pkg: "{{item.name}}"
  98. force: "{{item.force|default(omit)}}"
  99. conf_file: "{{item.yum_conf|default(omit)}}"
  100. state: present
  101. register: docker_task_result
  102. until: docker_task_result|succeeded
  103. retries: 4
  104. delay: "{{ retry_stagger | random + 3 }}"
  105. with_items: "{{ docker_package_info.pkgs }}"
  106. notify: restart docker
  107. when: not (ansible_os_family in ["CoreOS", "Container Linux by CoreOS"] or is_atomic) and (docker_package_info.pkgs|length > 0)
  108. - name: ensure service is started if docker packages are already present
  109. service:
  110. name: docker
  111. state: started
  112. when: docker_task_result is not changed
  113. - name: flush handlers so we can wait for docker to come up
  114. meta: flush_handlers
  115. - name: set fact for docker_version
  116. command: "docker version -f '{{ '{{' }}.Client.Version{{ '}}' }}'"
  117. register: installed_docker_version
  118. changed_when: false
  119. - name: check minimum docker version for docker_dns mode. You need at least docker version >= 1.12 for resolvconf_mode=docker_dns
  120. fail:
  121. msg: "You need at least docker version >= 1.12 for resolvconf_mode=docker_dns"
  122. when: >
  123. dns_mode != 'none' and
  124. resolvconf_mode == 'docker_dns' and
  125. installed_docker_version.stdout|version_compare('1.12', '<')
  126. - name: Set docker systemd config
  127. import_tasks: systemd.yml
  128. - name: ensure docker service is started and enabled
  129. service:
  130. name: "{{ item }}"
  131. enabled: yes
  132. state: started
  133. with_items:
  134. - docker