systemcontainer_docker.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. ---
  2. # If docker_options are provided we should fail. We should not install docker and ignore
  3. # the users configuration. NOTE: docker_options == inventory:openshift_docker_options
  4. - name: Fail quickly if openshift_docker_options are set
  5. assert:
  6. that:
  7. - docker_options is defined
  8. - docker_options != ""
  9. msg: |
  10. Docker via System Container does not allow for the use of the openshift_docker_options
  11. variable. If you want to use openshift_docker_options you will need to use the
  12. traditional docker package install. Otherwise, comment out openshift_docker_options
  13. in your inventory file.
  14. - name: Ensure container-selinux is installed
  15. package:
  16. name: container-selinux
  17. state: present
  18. when: not openshift.common.is_atomic | bool
  19. # Used to pull and install the system container
  20. - name: Ensure atomic is installed
  21. package:
  22. name: atomic
  23. state: present
  24. when: not openshift.common.is_atomic | bool
  25. # At the time of writing the atomic command requires runc for it's own use. This
  26. # task is here in the even that the atomic package ever removes the dependency.
  27. - name: Ensure runc is installed
  28. package:
  29. name: runc
  30. state: present
  31. when: not openshift.common.is_atomic | bool
  32. # Make sure Docker is installed so we are able to use the client
  33. - name: Install Docker so we can use the client
  34. package: name=docker{{ '-' + docker_version if docker_version is defined else '' }} state=present
  35. when: not openshift.common.is_atomic | bool
  36. # Make sure docker is disabled. Errors are ignored.
  37. - name: Disable Docker
  38. systemd:
  39. name: docker
  40. enabled: no
  41. state: stopped
  42. daemon_reload: yes
  43. ignore_errors: True
  44. register: r_docker_systemcontainer_docker_stop_result
  45. until: not r_docker_systemcontainer_docker_stop_result | failed
  46. retries: 3
  47. delay: 30
  48. # Set http_proxy, https_proxy, and no_proxy in /etc/atomic.conf
  49. # regexp: the line starts with or without #, followed by the string
  50. # http_proxy, then either : or =
  51. - block:
  52. - name: Add http_proxy to /etc/atomic.conf
  53. lineinfile:
  54. dest: /etc/atomic.conf
  55. regexp: "^#?http_proxy[:=]{1}"
  56. line: "http_proxy: {{ openshift.common.http_proxy | default('') }}"
  57. when:
  58. - openshift.common.http_proxy is defined
  59. - openshift.common.http_proxy != ''
  60. - name: Add https_proxy to /etc/atomic.conf
  61. lineinfile:
  62. dest: /etc/atomic.conf
  63. regexp: "^#?https_proxy[:=]{1}"
  64. line: "https_proxy: {{ openshift.common.https_proxy | default('') }}"
  65. when:
  66. - openshift.common.https_proxy is defined
  67. - openshift.common.https_proxy != ''
  68. - name: Add no_proxy to /etc/atomic.conf
  69. lineinfile:
  70. dest: /etc/atomic.conf
  71. regexp: "^#?no_proxy[:=]{1}"
  72. line: "no_proxy: {{ openshift.common.no_proxy | default('') }}"
  73. when:
  74. - openshift.common.no_proxy is defined
  75. - openshift.common.no_proxy != ''
  76. - block:
  77. - name: Set to default prepend
  78. set_fact:
  79. l_docker_image_prepend: "gscrivano"
  80. - name: Use Red Hat Registry for image when distribution is Red Hat
  81. set_fact:
  82. l_docker_image_prepend: "registry.access.redhat.com/openshift3"
  83. when: ansible_distribution == 'RedHat'
  84. - name: Use Fedora Registry for image when distribution is Fedora
  85. set_fact:
  86. l_docker_image_prepend: "registry.fedoraproject.org/f25"
  87. when: ansible_distribution == 'Fedora'
  88. # For https://github.com/openshift/openshift-ansible/pull/4049#discussion_r114478504
  89. - name: Use a testing registry if requested
  90. set_fact:
  91. l_docker_image_prepend: "{{ openshift_docker_systemcontainer_image_registry_override }}"
  92. when:
  93. - openshift_docker_systemcontainer_image_registry_override is defined
  94. - openshift_docker_systemcontainer_image_registry_override != ""
  95. - name: Set the full image name
  96. set_fact:
  97. l_docker_image: "{{ l_docker_image_prepend }}/{{ openshift.docker.service_name }}:latest"
  98. # NOTE: no_proxy added as a workaround until https://github.com/projectatomic/atomic/pull/999 is released
  99. - name: Pre-pull Container Engine System Container image
  100. command: "atomic pull --storage ostree {{ l_docker_image }}"
  101. changed_when: false
  102. environment:
  103. NO_PROXY: "{{ openshift.common.no_proxy | default('') }}"
  104. - name: Ensure container-engine.service.d directory exists
  105. file:
  106. path: "{{ container_engine_systemd_dir }}"
  107. state: directory
  108. - name: Ensure /etc/docker directory exists
  109. file:
  110. path: "{{ docker_conf_dir }}"
  111. state: directory
  112. - name: Install Container Engine System Container
  113. oc_atomic_container:
  114. name: "{{ openshift.docker.service_name }}"
  115. image: "{{ l_docker_image }}"
  116. state: latest
  117. - name: Configure Container Engine Service File
  118. template:
  119. dest: "{{ container_engine_systemd_dir }}/custom.conf"
  120. src: systemcontainercustom.conf.j2
  121. # Set local versions of facts that must be in json format for container-daemon.json
  122. # NOTE: When jinja2.9+ is used the container-daemon.json file can move to using tojson
  123. - set_fact:
  124. l_docker_insecure_registries: "{{ docker_insecure_registries | default([]) | to_json }}"
  125. l_docker_log_options: "{{ docker_log_options | default({}) | to_json }}"
  126. l_docker_additional_registries: "{{ docker_additional_registries | default([]) | to_json }}"
  127. l_docker_blocked_registries: "{{ docker_blocked_registries | default([]) | to_json }}"
  128. l_docker_selinux_enabled: "{{ docker_selinux_enabled | default(true) | to_json }}"
  129. # Configure container-engine using the container-daemon.json file
  130. # NOTE: daemon.json and container-daemon.json have been seperated to avoid
  131. # collision.
  132. - name: Configure Container Engine
  133. template:
  134. dest: "{{ docker_conf_dir }}/container-daemon.json"
  135. src: daemon.json
  136. # Enable and start the container-engine service
  137. - name: Start the Container Engine service
  138. systemd:
  139. name: "{{ openshift.docker.service_name }}"
  140. enabled: yes
  141. state: started
  142. daemon_reload: yes
  143. register: r_docker_systemcontainer_docker_start_result
  144. until: not r_docker_systemcontainer_docker_start_result | failed
  145. retries: 3
  146. delay: 30
  147. - set_fact:
  148. docker_service_status_changed: "{{ r_docker_systemcontainer_docker_start_result | changed }}"
  149. - meta: flush_handlers