package_docker.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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: "docker{{ '-' + docker_version if docker_version is defined else '' }}"
  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. - block:
  30. # Extend the default Docker service unit file when using iptables-services
  31. - name: Ensure docker.service.d directory exists
  32. file:
  33. path: "{{ docker_systemd_dir }}"
  34. state: directory
  35. - name: Configure Docker service unit file
  36. template:
  37. dest: "{{ docker_systemd_dir }}/custom.conf"
  38. src: custom.conf.j2
  39. notify:
  40. - restart container runtime
  41. when: not (os_firewall_use_firewalld | default(False)) | bool
  42. - stat: path=/etc/sysconfig/docker
  43. register: docker_check
  44. - name: Set registry params
  45. lineinfile:
  46. dest: /etc/sysconfig/docker
  47. regexp: '^{{ item.reg_conf_var }}=.*$'
  48. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | lib_utils_oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  49. when:
  50. - item.reg_fact_val != []
  51. - docker_check.stat.isreg is defined
  52. - docker_check.stat.isreg
  53. with_items:
  54. - reg_conf_var: ADD_REGISTRY
  55. reg_fact_val: "{{ l2_docker_additional_registries }}"
  56. reg_flag: --add-registry
  57. - reg_conf_var: BLOCK_REGISTRY
  58. reg_fact_val: "{{ l2_docker_blocked_registries }}"
  59. reg_flag: --block-registry
  60. - reg_conf_var: INSECURE_REGISTRY
  61. reg_fact_val: "{{ l2_docker_insecure_registries }}"
  62. reg_flag: --insecure-registry
  63. notify:
  64. - restart container runtime
  65. - name: Place additional/blocked/insecure registries in /etc/containers/registries.conf
  66. template:
  67. dest: "{{ containers_registries_conf_path }}"
  68. src: registries.conf
  69. when: openshift_docker_use_etc_containers | bool
  70. notify:
  71. - restart container runtime
  72. - name: Set Proxy Settings
  73. lineinfile:
  74. dest: /etc/sysconfig/docker
  75. regexp: '^{{ item.reg_conf_var }}=.*$'
  76. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  77. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  78. with_items:
  79. - reg_conf_var: HTTP_PROXY
  80. reg_fact_val: "{{ docker_http_proxy }}"
  81. - reg_conf_var: HTTPS_PROXY
  82. reg_fact_val: "{{ docker_https_proxy }}"
  83. - reg_conf_var: NO_PROXY
  84. reg_fact_val: "{{ docker_no_proxy }}"
  85. notify:
  86. - restart container runtime
  87. when:
  88. - docker_check.stat.isreg is defined
  89. - docker_check.stat.isreg
  90. - docker_http_proxy != '' or docker_https_proxy != ''
  91. - name: Set various Docker options
  92. lineinfile:
  93. dest: /etc/sysconfig/docker
  94. regexp: '^OPTIONS=.*$'
  95. line: "OPTIONS='\
  96. {% if ansible_selinux.status | default(None) == 'enabled' and openshift_docker_selinux_enabled | default(true) | bool %} --selinux-enabled {% endif %} \
  97. {% if openshift_docker_log_driver %} --log-driver {{ openshift_docker_log_driver }}{% endif %} \
  98. {% if l2_docker_log_options != [] %} {{ l2_docker_log_options | lib_utils_oo_split() | lib_utils_oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %} \
  99. {% if (openshift_docker_hosted_registry_insecure | bool) and openshift_docker_hosted_registry_network %} --insecure-registry={{ openshift_docker_hosted_registry_network }} {% endif %} \
  100. {% if docker_options is defined %} {{ docker_options }}{% endif %} \
  101. {% if openshift_docker_options %} {{ openshift_docker_options }}{% endif %} \
  102. --signature-verification={{ openshift_docker_signature_verification | bool }}'"
  103. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  104. notify:
  105. - restart container runtime
  106. - stat: path=/etc/sysconfig/docker-network
  107. register: sysconfig_docker_network_check
  108. - name: Configure Docker Network OPTIONS
  109. lineinfile:
  110. dest: /etc/sysconfig/docker-network
  111. regexp: '^DOCKER_NETWORK_OPTIONS=.*$'
  112. line: "DOCKER_NETWORK_OPTIONS='\
  113. {% if openshift.node is defined and openshift.node.sdn_mtu is defined %} --mtu={{ openshift.node.sdn_mtu }}{% endif %}'"
  114. when:
  115. - sysconfig_docker_network_check.stat.isreg is defined
  116. - sysconfig_docker_network_check.stat.isreg
  117. notify:
  118. - restart container runtime
  119. # The following task is needed as the systemd module may report a change in
  120. # state even though docker is already running.
  121. - name: Detect if docker is already started
  122. command: "systemctl show docker -p ActiveState"
  123. changed_when: False
  124. register: r_docker_already_running_result
  125. - name: Start the Docker service
  126. systemd:
  127. name: docker
  128. enabled: yes
  129. state: started
  130. daemon_reload: yes
  131. register: r_docker_package_docker_start_result
  132. until: not (r_docker_package_docker_start_result is failed)
  133. retries: 3
  134. delay: 30
  135. - set_fact:
  136. docker_service_status_changed: "{{ (r_docker_package_docker_start_result is changed) and (r_docker_already_running_result.stdout != 'ActiveState=active' ) }}"
  137. - import_tasks: common/post.yml