package_docker.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. notify:
  75. - restart docker
  76. - name: Set Proxy Settings
  77. lineinfile:
  78. dest: /etc/sysconfig/docker
  79. regexp: '^{{ item.reg_conf_var }}=.*$'
  80. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  81. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  82. with_items:
  83. - reg_conf_var: HTTP_PROXY
  84. reg_fact_val: "{{ docker_http_proxy | default('') }}"
  85. - reg_conf_var: HTTPS_PROXY
  86. reg_fact_val: "{{ docker_https_proxy | default('') }}"
  87. - reg_conf_var: NO_PROXY
  88. reg_fact_val: "{{ docker_no_proxy | default('') }}"
  89. notify:
  90. - restart docker
  91. when:
  92. - docker_check.stat.isreg is defined and docker_check.stat.isreg and '"http_proxy" in openshift.common or "https_proxy" in openshift.common'
  93. - name: Set various Docker options
  94. lineinfile:
  95. dest: /etc/sysconfig/docker
  96. regexp: '^OPTIONS=.*$'
  97. line: "OPTIONS='\
  98. {% if ansible_selinux.status | default(None) == 'enabled' and docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %} \
  99. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %} \
  100. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %} \
  101. {% if docker_options is defined %} {{ docker_options }}{% endif %} \
  102. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %} \
  103. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  104. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  105. notify:
  106. - restart docker
  107. - stat: path=/etc/sysconfig/docker-network
  108. register: sysconfig_docker_network_check
  109. - name: Configure Docker Network OPTIONS
  110. lineinfile:
  111. dest: /etc/sysconfig/docker-network
  112. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  113. line: "DOCKER_NETWORK_OPTIONS='\
  114. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  115. when:
  116. - sysconfig_docker_network_check.stat.isreg is defined
  117. - sysconfig_docker_network_check.stat.isreg
  118. notify:
  119. - restart docker
  120. # The following task is needed as the systemd module may report a change in
  121. # state even though docker is already running.
  122. - name: Detect if docker is already started
  123. command: "systemctl show docker -p ActiveState"
  124. changed_when: False
  125. register: r_docker_already_running_result
  126. - name: Start the Docker service
  127. systemd:
  128. name: docker
  129. enabled: yes
  130. state: started
  131. daemon_reload: yes
  132. register: r_docker_package_docker_start_result
  133. until: not r_docker_package_docker_start_result | failed
  134. retries: 3
  135. delay: 30
  136. - set_fact:
  137. docker_service_status_changed: "{{ (r_docker_package_docker_start_result | changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  138. - name: Check for credentials file for registry auth
  139. stat:
  140. path: "{{ docker_cli_auth_config_path }}/config.json"
  141. when: oreg_auth_user is defined
  142. register: docker_cli_auth_credentials_stat
  143. - name: Create credentials for docker cli registry auth
  144. command: "docker --config={{ docker_cli_auth_config_path }} login -u {{ oreg_auth_user }} -p {{ oreg_auth_password }} {{ oreg_host }}"
  145. when:
  146. - oreg_auth_user is defined
  147. - (not docker_cli_auth_credentials_stat.stat.exists or oreg_auth_credentials_replace) | bool
  148. - meta: flush_handlers