systemcontainer_docker.yml 6.3 KB

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