package_docker.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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: "{{ l_docker_pkg_list | join(',') }}"
  22. state: present
  23. when:
  24. - not (openshift_is_atomic | bool)
  25. - not (curr_docker_version is skipped)
  26. - not (curr_docker_version.stdout != '')
  27. register: result
  28. until: result is succeeded
  29. vars:
  30. l_docker_pkg_list:
  31. - "docker{{ '-' + docker_version if docker_version is defined else '' }}"
  32. - atomic
  33. - skopeo
  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 container runtime
  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 | lib_utils_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 container runtime
  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 container runtime
  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 }}"
  86. - reg_conf_var: HTTPS_PROXY
  87. reg_fact_val: "{{ docker_https_proxy }}"
  88. - reg_conf_var: NO_PROXY
  89. reg_fact_val: "{{ docker_no_proxy }}"
  90. notify:
  91. - restart container runtime
  92. when:
  93. - docker_check.stat.isreg is defined
  94. - docker_check.stat.isreg
  95. - docker_http_proxy != '' or docker_https_proxy != ''
  96. - name: Set various Docker options
  97. lineinfile:
  98. dest: /etc/sysconfig/docker
  99. regexp: '^OPTIONS=.*$'
  100. line: "OPTIONS='\
  101. {% if ansible_selinux.status | default(None) == 'enabled' and openshift_docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %} \
  102. {% if openshift_docker_log_driver %} --log-driver {{ openshift_docker_log_driver }}{% endif %} \
  103. {% if l2_docker_log_options != [] %} {{ l2_docker_log_options | lib_utils_oo_split() | lib_utils_oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %} \
  104. {% if (openshift_docker_hosted_registry_insecure | bool) and openshift_docker_hosted_registry_network %} --insecure-registry={{ openshift_docker_hosted_registry_network }} {% endif %} \
  105. {% if docker_options is defined %} {{ docker_options }}{% endif %} \
  106. {% if openshift_docker_options %} {{ openshift_docker_options }}{% endif %} \
  107. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  108. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  109. notify:
  110. - restart container runtime
  111. - stat: path=/etc/sysconfig/docker-network
  112. register: sysconfig_docker_network_check
  113. - name: Configure Docker Network OPTIONS
  114. lineinfile:
  115. dest: /etc/sysconfig/docker-network
  116. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  117. line: "DOCKER_NETWORK_OPTIONS='\
  118. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  119. when:
  120. - sysconfig_docker_network_check.stat.isreg is defined
  121. - sysconfig_docker_network_check.stat.isreg
  122. notify:
  123. - restart container runtime
  124. # The following task is needed as the systemd module may report a change in
  125. # state even though docker is already running.
  126. - name: Detect if docker is already started
  127. command: "systemctl show docker -p ActiveState"
  128. changed_when: False
  129. register: r_docker_already_running_result
  130. - name: Start the Docker service
  131. systemd:
  132. name: docker
  133. enabled: yes
  134. state: started
  135. daemon_reload: yes
  136. register: r_docker_package_docker_start_result
  137. until: not (r_docker_package_docker_start_result is failed)
  138. retries: 3
  139. delay: 30
  140. - set_fact:
  141. docker_service_status_changed: "{{ (r_docker_package_docker_start_result is changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  142. - name: Check for docker_storage_path/overlay2
  143. stat:
  144. path: "{{ docker_storage_path }}/overlay2"
  145. register: dsp_stat
  146. - name: Fixup SELinux permissions for docker
  147. shell: |
  148. semanage fcontext -a -e /var/lib/docker/overlay2 "{{ docker_storage_path }}/overlay2"
  149. restorecon -R -v "{{ docker_storage_path }}/overlay2"
  150. when: dsp_stat.stat.exists
  151. - import_tasks: common/post.yml