systemcontainer_docker.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. l_docker_image_tag: "latest"
  81. - name: Set container engine image tag
  82. set_fact:
  83. l_docker_image_tag: "{{ openshift_image_tag }}"
  84. when:
  85. - openshift_deployment_type == 'openshift-enterprise'
  86. - openshift_image_tag is defined
  87. - name: Use Red Hat Registry for image when distribution is Red Hat
  88. set_fact:
  89. l_docker_image_prepend: "registry.access.redhat.com/openshift3"
  90. when: ansible_distribution == 'RedHat'
  91. - name: Use Fedora Registry for image when distribution is Fedora
  92. set_fact:
  93. l_docker_image_prepend: "registry.fedoraproject.org/f25"
  94. when: ansible_distribution == 'Fedora'
  95. - name: Set the full image name
  96. set_fact:
  97. l_docker_image: "{{ l_docker_image_prepend }}/{{ openshift.docker.service_name }}:{{ l_docker_image_tag }}"
  98. # For https://github.com/openshift/openshift-ansible/pull/5354#issuecomment-328552959
  99. - name: Use a specific image if requested
  100. set_fact:
  101. l_docker_image: "{{ openshift_docker_systemcontainer_image_override }}"
  102. when:
  103. - openshift_docker_systemcontainer_image_override is defined
  104. - openshift_docker_systemcontainer_image_override != ""
  105. # Be nice and let the user see the variable result
  106. - debug:
  107. var: l_docker_image
  108. # NOTE: no_proxy added as a workaround until https://github.com/projectatomic/atomic/pull/999 is released
  109. - name: Pre-pull Container Engine System Container image
  110. command: "atomic pull --storage ostree {{ l_docker_image }}"
  111. changed_when: false
  112. environment:
  113. NO_PROXY: "{{ openshift.common.no_proxy | default('') }}"
  114. - name: Ensure container-engine.service.d directory exists
  115. file:
  116. path: "{{ container_engine_systemd_dir }}"
  117. state: directory
  118. - name: Ensure /etc/docker directory exists
  119. file:
  120. path: "{{ docker_conf_dir }}"
  121. state: directory
  122. - name: Install Container Engine System Container
  123. oc_atomic_container:
  124. name: "{{ openshift.docker.service_name }}"
  125. image: "{{ l_docker_image }}"
  126. state: latest
  127. - name: Configure Container Engine Service File
  128. template:
  129. dest: "{{ container_engine_systemd_dir }}/custom.conf"
  130. src: systemcontainercustom.conf.j2
  131. # Set local versions of facts that must be in json format for container-daemon.json
  132. # NOTE: When jinja2.9+ is used the container-daemon.json file can move to using tojson
  133. - set_fact:
  134. l_docker_insecure_registries: "{{ l2_docker_insecure_registries | default([]) | to_json }}"
  135. l_docker_log_options: "{{ docker_log_options | default({}) | to_json }}"
  136. l_docker_additional_registries: "{{ l2_docker_additional_registries | default([]) | to_json }}"
  137. l_docker_blocked_registries: "{{ l2_docker_blocked_registries | default([]) | to_json }}"
  138. l_docker_selinux_enabled: "{{ docker_selinux_enabled | default(true) | to_json }}"
  139. # Configure container-engine using the container-daemon.json file
  140. # NOTE: daemon.json and container-daemon.json have been seperated to avoid
  141. # collision.
  142. - name: Configure Container Engine
  143. template:
  144. dest: "{{ docker_conf_dir }}/container-daemon.json"
  145. src: daemon.json
  146. # Enable and start the container-engine service
  147. - name: Start the Container Engine service
  148. systemd:
  149. name: "{{ openshift.docker.service_name }}"
  150. enabled: yes
  151. state: started
  152. daemon_reload: yes
  153. register: r_docker_systemcontainer_docker_start_result
  154. until: not r_docker_systemcontainer_docker_start_result | failed
  155. retries: 3
  156. delay: 30
  157. - set_fact:
  158. docker_service_status_changed: "{{ r_docker_systemcontainer_docker_start_result | changed }}"
  159. - meta: flush_handlers