package_docker.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ---
  2. - name: Get current installed Docker version
  3. command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
  4. when: not openshift.common.is_atomic | bool
  5. register: curr_docker_version
  6. retries: 4
  7. until: curr_docker_version | succeeded
  8. changed_when: false
  9. - name: Error out if Docker pre-installed but too old
  10. fail:
  11. msg: "Docker {{ curr_docker_version.stdout }} is installed, but >= 1.9.1 is required."
  12. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and curr_docker_version.stdout | version_compare('1.9.1', '<') and not docker_version is defined
  13. - name: Error out if requested Docker is too old
  14. fail:
  15. msg: "Docker {{ docker_version }} requested, but >= 1.9.1 is required."
  16. when: docker_version is defined and docker_version | version_compare('1.9.1', '<')
  17. # If a docker_version was requested, sanity check that we can install or upgrade to it, and
  18. # no downgrade is required.
  19. - name: Fail if Docker version requested but downgrade is required
  20. fail:
  21. msg: "Docker {{ curr_docker_version.stdout }} is installed, but version {{ docker_version }} was requested."
  22. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and docker_version is defined and curr_docker_version.stdout | version_compare(docker_version, '>')
  23. # This involves an extremely slow migration process, users should instead run the
  24. # Docker 1.10 upgrade playbook to accomplish this.
  25. - name: Error out if attempting to upgrade Docker across the 1.10 boundary
  26. fail:
  27. msg: "Cannot upgrade Docker to >= 1.10, please upgrade or remove Docker manually, or use the Docker upgrade playbook if OpenShift is already installed."
  28. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and curr_docker_version.stdout | version_compare('1.10', '<') and docker_version is defined and docker_version | version_compare('1.10', '>=')
  29. # Make sure Docker is installed, but does not update a running version.
  30. # Docker upgrades are handled by a separate playbook.
  31. - name: Install Docker
  32. package: name=docker{{ '-' + docker_version if docker_version is defined else '' }} state=present
  33. when: not openshift.common.is_atomic | bool
  34. - block:
  35. # Extend the default Docker service unit file when using iptables-services
  36. - name: Ensure docker.service.d directory exists
  37. file:
  38. path: "{{ docker_systemd_dir }}"
  39. state: directory
  40. - name: Configure Docker service unit file
  41. template:
  42. dest: "{{ docker_systemd_dir }}/custom.conf"
  43. src: custom.conf.j2
  44. notify:
  45. - restart docker
  46. when: not (os_firewall_use_firewalld | default(False)) | bool
  47. - stat: path=/etc/sysconfig/docker
  48. register: docker_check
  49. - name: Set registry params
  50. lineinfile:
  51. dest: /etc/sysconfig/docker
  52. regexp: '^{{ item.reg_conf_var }}=.*$'
  53. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  54. when:
  55. - item.reg_fact_val != []
  56. - docker_check.stat.isreg is defined
  57. - docker_check.stat.isreg
  58. with_items:
  59. - reg_conf_var: ADD_REGISTRY
  60. reg_fact_val: "{{ l2_docker_additional_registries }}"
  61. reg_flag: --add-registry
  62. - reg_conf_var: BLOCK_REGISTRY
  63. reg_fact_val: "{{ l2_docker_blocked_registries }}"
  64. reg_flag: --block-registry
  65. - reg_conf_var: INSECURE_REGISTRY
  66. reg_fact_val: "{{ l2_docker_insecure_registries }}"
  67. reg_flag: --insecure-registry
  68. notify:
  69. - restart docker
  70. - name: Place additional/blocked/insecure registries in /etc/containers/registries.conf
  71. template:
  72. dest: "{{ containers_registries_conf_path }}"
  73. src: registries.conf
  74. when: openshift_docker_use_etc_containers | bool
  75. notify:
  76. - restart docker
  77. - name: Set Proxy Settings
  78. lineinfile:
  79. dest: /etc/sysconfig/docker
  80. regexp: '^{{ item.reg_conf_var }}=.*$'
  81. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  82. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  83. with_items:
  84. - reg_conf_var: HTTP_PROXY
  85. reg_fact_val: "{{ docker_http_proxy | default('') }}"
  86. - reg_conf_var: HTTPS_PROXY
  87. reg_fact_val: "{{ docker_https_proxy | default('') }}"
  88. - reg_conf_var: NO_PROXY
  89. reg_fact_val: "{{ docker_no_proxy | default('') }}"
  90. notify:
  91. - restart docker
  92. when:
  93. - docker_check.stat.isreg is defined and docker_check.stat.isreg and '"http_proxy" in openshift.common or "https_proxy" in openshift.common'
  94. - name: Set various Docker options
  95. lineinfile:
  96. dest: /etc/sysconfig/docker
  97. regexp: '^OPTIONS=.*$'
  98. line: "OPTIONS='\
  99. {% if ansible_selinux.status | default(None) == 'enabled' and docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %} \
  100. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %} \
  101. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %} \
  102. {% if docker_options is defined %} {{ docker_options }}{% endif %} \
  103. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %} \
  104. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  105. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  106. notify:
  107. - restart docker
  108. - stat: path=/etc/sysconfig/docker-network
  109. register: sysconfig_docker_network_check
  110. - name: Configure Docker Network OPTIONS
  111. lineinfile:
  112. dest: /etc/sysconfig/docker-network
  113. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  114. line: "DOCKER_NETWORK_OPTIONS='\
  115. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  116. when:
  117. - sysconfig_docker_network_check.stat.isreg is defined
  118. - sysconfig_docker_network_check.stat.isreg
  119. notify:
  120. - restart docker
  121. # The following task is needed as the systemd module may report a change in
  122. # state even though docker is already running.
  123. - name: Detect if docker is already started
  124. command: "systemctl show docker -p ActiveState"
  125. changed_when: False
  126. register: r_docker_already_running_result
  127. - name: Start the Docker service
  128. systemd:
  129. name: docker
  130. enabled: yes
  131. state: started
  132. daemon_reload: yes
  133. register: r_docker_package_docker_start_result
  134. until: not r_docker_package_docker_start_result | failed
  135. retries: 3
  136. delay: 30
  137. - set_fact:
  138. docker_service_status_changed: "{{ (r_docker_package_docker_start_result | changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  139. - include: registry_auth.yml
  140. - meta: flush_handlers