systemcontainer_docker.yml 6.9 KB

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