package_docker.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ---
  2. - include_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. - include_tasks: common/atomic_proxy.yml
  6. when:
  7. - >
  8. (openshift_use_system_containers | default(False)) | bool
  9. or (openshift_use_etcd_system_container | default(False)) | bool
  10. or (openshift_use_openvswitch_system_container | default(False)) | bool
  11. or (openshift_use_node_system_container | default(False)) | bool
  12. or (openshift_use_master_system_container | default(False)) | bool
  13. - name: Get current installed Docker version
  14. command: "{{ repoquery_installed }} --qf '%{version}' docker"
  15. when: not openshift_is_atomic | bool
  16. register: curr_docker_version
  17. retries: 4
  18. until: curr_docker_version is succeeded
  19. changed_when: false
  20. # Some basic checks to ensure the role will complete
  21. - include_tasks: docker_sanity.yml
  22. # Make sure Docker is installed, but does not update a running version.
  23. # Docker upgrades are handled by a separate playbook.
  24. # Note: The curr_docker_version.stdout check can be removed when https://github.com/ansible/ansible/issues/33187 gets fixed.
  25. - name: Install Docker
  26. package:
  27. name: "docker{{ '-' + docker_version if docker_version is defined else '' }}"
  28. state: present
  29. when:
  30. - not (openshift_is_atomic | bool)
  31. - not (curr_docker_version is skipped)
  32. - not (curr_docker_version.stdout != '')
  33. register: result
  34. until: result is succeeded
  35. - block:
  36. # Extend the default Docker service unit file when using iptables-services
  37. - name: Ensure docker.service.d directory exists
  38. file:
  39. path: "{{ docker_systemd_dir }}"
  40. state: directory
  41. - name: Configure Docker service unit file
  42. template:
  43. dest: "{{ docker_systemd_dir }}/custom.conf"
  44. src: custom.conf.j2
  45. notify:
  46. - restart container runtime
  47. when: not (os_firewall_use_firewalld | default(False)) | bool
  48. - stat: path=/etc/sysconfig/docker
  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 | bool %} --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 and (openshift_docker_hosted_registry_network | bool) %} --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. {% if openshift_docker_disable_push_dockerhub %} --confirm-def-push={{ openshift_docker_disable_push_dockerhub | bool }}{% endif %} \
  109. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  110. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  111. notify:
  112. - restart container runtime
  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 container runtime
  126. # The following task is needed as the systemd module may report a change in
  127. # state even though docker is already running.
  128. - name: Detect if docker is already started
  129. command: "systemctl show docker -p ActiveState"
  130. changed_when: False
  131. register: r_docker_already_running_result
  132. - name: Start the Docker service
  133. systemd:
  134. name: docker
  135. enabled: yes
  136. state: started
  137. daemon_reload: yes
  138. register: r_docker_package_docker_start_result
  139. until: not (r_docker_package_docker_start_result is failed)
  140. retries: 3
  141. delay: 30
  142. - set_fact:
  143. docker_service_status_changed: "{{ (r_docker_package_docker_start_result is changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  144. - include_tasks: common/post.yml