package_docker.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ---
  2. - import_tasks: common/pre.yml
  3. # In some cases, some services may be run as containers and docker may still
  4. # be installed via rpm.
  5. - import_tasks: common/atomic_proxy.yml
  6. when: openshift_is_atomic
  7. - name: Get current installed Docker version
  8. command: "{{ repoquery_installed }} --qf '%{version}' docker"
  9. when: not openshift_is_atomic | bool
  10. register: curr_docker_version
  11. retries: 4
  12. until: curr_docker_version is succeeded
  13. changed_when: false
  14. # Some basic checks to ensure the role will complete
  15. - import_tasks: docker_sanity.yml
  16. # Make sure Docker is installed, but does not update a running version.
  17. # Docker upgrades are handled by a separate playbook.
  18. # Note: The curr_docker_version.stdout check can be removed when https://github.com/ansible/ansible/issues/33187 gets fixed.
  19. - name: Install Docker
  20. package:
  21. name: "{{ pkg_list | join(',') }}"
  22. state: present
  23. when:
  24. - not (openshift_is_atomic | bool)
  25. register: result
  26. until: result is succeeded
  27. vars:
  28. pkg_list:
  29. - "docker{{ '-' + docker_version if docker_version is defined else '' }}"
  30. - atomic
  31. - skopeo
  32. - block:
  33. # Extend the default Docker service unit file when using iptables-services
  34. - name: Ensure docker.service.d directory exists
  35. file:
  36. path: "{{ docker_systemd_dir }}"
  37. state: directory
  38. - name: Configure Docker service unit file
  39. template:
  40. dest: "{{ docker_systemd_dir }}/custom.conf"
  41. src: custom.conf.j2
  42. notify:
  43. - restart container runtime
  44. when: not (os_firewall_use_firewalld | default(False)) | bool
  45. - stat:
  46. path: /etc/sysconfig/docker
  47. get_checksum: false
  48. get_mime: false
  49. register: docker_check
  50. - name: Set registry params
  51. lineinfile:
  52. dest: /etc/sysconfig/docker
  53. regexp: '^{{ item.reg_conf_var }}=.*$'
  54. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | lib_utils_oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  55. when:
  56. - item.reg_fact_val != []
  57. - docker_check.stat.isreg is defined
  58. - docker_check.stat.isreg
  59. with_items:
  60. - reg_conf_var: ADD_REGISTRY
  61. reg_fact_val: "{{ l2_docker_additional_registries }}"
  62. reg_flag: --add-registry
  63. - reg_conf_var: BLOCK_REGISTRY
  64. reg_fact_val: "{{ l2_docker_blocked_registries }}"
  65. reg_flag: --block-registry
  66. - reg_conf_var: INSECURE_REGISTRY
  67. reg_fact_val: "{{ l2_docker_insecure_registries }}"
  68. reg_flag: --insecure-registry
  69. notify:
  70. - restart container runtime
  71. - name: Place additional/blocked/insecure registries in /etc/containers/registries.conf
  72. template:
  73. dest: "{{ containers_registries_conf_path }}"
  74. src: registries.conf
  75. when: openshift_docker_use_etc_containers | bool
  76. notify:
  77. - restart container runtime
  78. - name: Set Proxy Settings
  79. lineinfile:
  80. dest: /etc/sysconfig/docker
  81. regexp: '^{{ item.reg_conf_var }}=.*$'
  82. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  83. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  84. with_items:
  85. - reg_conf_var: HTTP_PROXY
  86. reg_fact_val: "{{ docker_http_proxy }}"
  87. - reg_conf_var: HTTPS_PROXY
  88. reg_fact_val: "{{ docker_https_proxy }}"
  89. - reg_conf_var: NO_PROXY
  90. reg_fact_val: "{{ docker_no_proxy }}"
  91. notify:
  92. - restart container runtime
  93. when:
  94. - docker_check.stat.isreg is defined
  95. - docker_check.stat.isreg
  96. - docker_http_proxy != '' or docker_https_proxy != ''
  97. - name: Set various Docker options
  98. lineinfile:
  99. dest: /etc/sysconfig/docker
  100. regexp: '^OPTIONS=.*$'
  101. line: "OPTIONS='\
  102. {% if ansible_selinux.status | default(None) == 'enabled' and openshift_docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %} \
  103. {% if openshift_docker_log_driver %} --log-driver {{ openshift_docker_log_driver }}{% endif %} \
  104. {% if l2_docker_log_options != [] %} {{ l2_docker_log_options | lib_utils_oo_split() | lib_utils_oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %} \
  105. {% if (openshift_docker_hosted_registry_insecure | bool) and openshift_docker_hosted_registry_network %} --insecure-registry={{ openshift_docker_hosted_registry_network }} {% endif %} \
  106. {% if docker_options is defined %} {{ docker_options }}{% endif %} \
  107. {% if openshift_docker_options %} {{ openshift_docker_options }}{% endif %} \
  108. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  109. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  110. notify:
  111. - restart container runtime
  112. - stat:
  113. path: /etc/sysconfig/docker-network
  114. get_checksum: false
  115. get_mime: false
  116. register: sysconfig_docker_network_check
  117. - name: Configure Docker Network OPTIONS
  118. lineinfile:
  119. dest: /etc/sysconfig/docker-network
  120. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  121. line: "DOCKER_NETWORK_OPTIONS='\
  122. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  123. when:
  124. - sysconfig_docker_network_check.stat.isreg is defined
  125. - sysconfig_docker_network_check.stat.isreg
  126. notify:
  127. - restart container runtime
  128. # The following task is needed as the systemd module may report a change in
  129. # state even though docker is already running.
  130. - name: Detect if docker is already started
  131. command: "systemctl show docker -p ActiveState"
  132. changed_when: False
  133. register: r_docker_already_running_result
  134. - name: Start the Docker service
  135. systemd:
  136. name: docker
  137. enabled: yes
  138. state: started
  139. daemon_reload: yes
  140. register: r_docker_package_docker_start_result
  141. until: not (r_docker_package_docker_start_result is failed)
  142. retries: 3
  143. delay: 30
  144. - set_fact:
  145. docker_service_status_changed: "{{ (r_docker_package_docker_start_result is changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  146. - name: Check for docker_storage_path/overlay2
  147. stat:
  148. path: "{{ docker_storage_path }}/overlay2"
  149. register: dsp_stat
  150. - name: Fixup SELinux permissions for docker
  151. shell: |
  152. semanage fcontext -a -e /var/lib/docker/overlay2 "{{ docker_storage_path }}/overlay2"
  153. restorecon -R -v "{{ docker_storage_path }}/overlay2"
  154. when: dsp_stat.stat.exists
  155. - import_tasks: common/post.yml