package_docker.yml 6.8 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. - name: Add enterprise registry, if necessary
  48. set_fact:
  49. l2_docker_additional_registries: "{{ l2_docker_additional_registries + [openshift_docker_ent_reg] }}"
  50. when:
  51. - openshift.common.deployment_type == 'openshift-enterprise'
  52. - openshift_docker_ent_reg != ''
  53. - openshift_docker_ent_reg not in l2_docker_additional_registries
  54. - stat: path=/etc/sysconfig/docker
  55. register: docker_check
  56. - name: Set registry params
  57. lineinfile:
  58. dest: /etc/sysconfig/docker
  59. regexp: '^{{ item.reg_conf_var }}=.*$'
  60. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  61. when:
  62. - item.reg_fact_val != []
  63. - docker_check.stat.isreg is defined
  64. - docker_check.stat.isreg
  65. with_items:
  66. - reg_conf_var: ADD_REGISTRY
  67. reg_fact_val: "{{ l2_docker_additional_registries }}"
  68. reg_flag: --add-registry
  69. - reg_conf_var: BLOCK_REGISTRY
  70. reg_fact_val: "{{ l2_docker_blocked_registries }}"
  71. reg_flag: --block-registry
  72. - reg_conf_var: INSECURE_REGISTRY
  73. reg_fact_val: "{{ l2_docker_insecure_registries }}"
  74. reg_flag: --insecure-registry
  75. notify:
  76. - restart docker
  77. - name: Place additional/blocked/insecure registries in /etc/containers/registries.conf
  78. template:
  79. dest: "{{ containers_registries_conf_path }}"
  80. src: registries.conf
  81. notify:
  82. - restart docker
  83. - name: Set Proxy Settings
  84. lineinfile:
  85. dest: /etc/sysconfig/docker
  86. regexp: '^{{ item.reg_conf_var }}=.*$'
  87. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  88. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  89. with_items:
  90. - reg_conf_var: HTTP_PROXY
  91. reg_fact_val: "{{ docker_http_proxy | default('') }}"
  92. - reg_conf_var: HTTPS_PROXY
  93. reg_fact_val: "{{ docker_https_proxy | default('') }}"
  94. - reg_conf_var: NO_PROXY
  95. reg_fact_val: "{{ docker_no_proxy | default('') }}"
  96. notify:
  97. - restart docker
  98. when:
  99. - docker_check.stat.isreg is defined and docker_check.stat.isreg and '"http_proxy" in openshift.common or "https_proxy" in openshift.common'
  100. - name: Set various Docker options
  101. lineinfile:
  102. dest: /etc/sysconfig/docker
  103. regexp: '^OPTIONS=.*$'
  104. line: "OPTIONS='\
  105. {% if ansible_selinux.status | default(None) == 'enabled' and docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %}\
  106. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %}\
  107. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %}\
  108. {% if docker_options is defined %} {{ docker_options }}{% endif %}\
  109. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %}'"
  110. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  111. notify:
  112. - restart docker
  113. - stat: path=/etc/sysconfig/docker-network
  114. register: sysconfig_docker_network_check
  115. - name: Configure Docker Network OPTIONS
  116. lineinfile:
  117. dest: /etc/sysconfig/docker-network
  118. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  119. line: "DOCKER_NETWORK_OPTIONS='\
  120. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  121. when:
  122. - sysconfig_docker_network_check.stat.isreg is defined
  123. - sysconfig_docker_network_check.stat.isreg
  124. notify:
  125. - restart docker
  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 }}"
  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