package_docker.yml 5.6 KB

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