systemcontainer_docker.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # Set http_proxy, https_proxy, and no_proxy in /etc/atomic.conf
  45. # regexp: the line starts with or without #, followed by the string
  46. # http_proxy, then either : or =
  47. - block:
  48. - name: Add http_proxy to /etc/atomic.conf
  49. lineinfile:
  50. dest: /etc/atomic.conf
  51. regexp: "^#?http_proxy[:=]{1}"
  52. line: "http_proxy: {{ openshift.common.http_proxy | default('') }}"
  53. when:
  54. - openshift.common.http_proxy is defined
  55. - openshift.common.http_proxy != ''
  56. - name: Add https_proxy to /etc/atomic.conf
  57. lineinfile:
  58. dest: /etc/atomic.conf
  59. regexp: "^#?https_proxy[:=]{1}"
  60. line: "https_proxy: {{ openshift.common.https_proxy | default('') }}"
  61. when:
  62. - openshift.common.https_proxy is defined
  63. - openshift.common.https_proxy != ''
  64. - name: Add no_proxy to /etc/atomic.conf
  65. lineinfile:
  66. dest: /etc/atomic.conf
  67. regexp: "^#?no_proxy[:=]{1}"
  68. line: "no_proxy: {{ openshift.common.no_proxy | default('') }}"
  69. when:
  70. - openshift.common.no_proxy is defined
  71. - openshift.common.no_proxy != ''
  72. - block:
  73. - name: Set to default prepend
  74. set_fact:
  75. l_docker_image_prepend: "gscrivano"
  76. - name: Use Red Hat Registry for image when distribution is Red Hat
  77. set_fact:
  78. l_docker_image_prepend: "registry.access.redhat.com/openshift3"
  79. when: ansible_distribution == 'RedHat'
  80. - name: Use Fedora Registry for image when distribution is Fedora
  81. set_fact:
  82. l_docker_image_prepend: "registry.fedoraproject.org"
  83. when: ansible_distribution == 'Fedora'
  84. # For https://github.com/openshift/openshift-ansible/pull/4049#discussion_r114478504
  85. - name: Use a testing registry if requested
  86. set_fact:
  87. l_docker_image_prepend: "{{ openshift_docker_systemcontainer_image_registry_override }}"
  88. when:
  89. - openshift_docker_systemcontainer_image_registry_override is defined
  90. - openshift_docker_systemcontainer_image_registry_override != ""
  91. - name: Set the full image name
  92. set_fact:
  93. l_docker_image: "{{ l_docker_image_prepend }}/{{ openshift.docker.service_name }}:latest"
  94. # NOTE: no_proxy added as a workaround until https://github.com/projectatomic/atomic/pull/999 is released
  95. - name: Pre-pull Container Engine System Container image
  96. command: "atomic pull --storage ostree {{ l_docker_image }}"
  97. changed_when: false
  98. environment:
  99. NO_PROXY: "{{ openshift.common.no_proxy | default('') }}"
  100. - name: Ensure container-engine.service.d directory exists
  101. file:
  102. path: "{{ container_engine_systemd_dir }}"
  103. state: directory
  104. - name: Ensure /etc/docker directory exists
  105. file:
  106. path: "{{ docker_conf_dir }}"
  107. state: directory
  108. - name: Install Container Engine System Container
  109. oc_atomic_container:
  110. name: "{{ openshift.docker.service_name }}"
  111. image: "{{ l_docker_image }}"
  112. state: latest
  113. - name: Configure Container Engine Service File
  114. template:
  115. dest: "{{ container_engine_systemd_dir }}/custom.conf"
  116. src: systemcontainercustom.conf.j2
  117. # Set local versions of facts that must be in json format for container-daemon.json
  118. # NOTE: When jinja2.9+ is used the container-daemon.json file can move to using tojson
  119. - set_fact:
  120. l_docker_insecure_registries: "{{ docker_insecure_registries | default([]) | to_json }}"
  121. l_docker_log_options: "{{ docker_log_options | default({}) | to_json }}"
  122. l_docker_additional_registries: "{{ docker_additional_registries | default([]) | to_json }}"
  123. l_docker_blocked_registries: "{{ docker_blocked_registries | default([]) | to_json }}"
  124. l_docker_selinux_enabled: "{{ docker_selinux_enabled | default(true) | to_json }}"
  125. # Configure container-engine using the container-daemon.json file
  126. # NOTE: daemon.json and container-daemon.json have been seperated to avoid
  127. # collision.
  128. - name: Configure Container Engine
  129. template:
  130. dest: "{{ docker_conf_dir }}/container-daemon.json"
  131. src: daemon.json
  132. # Enable and start the container-engine service
  133. - name: Start the Container Engine service
  134. systemd:
  135. name: "{{ openshift.docker.service_name }}"
  136. enabled: yes
  137. state: started
  138. daemon_reload: yes
  139. register: start_result
  140. - set_fact:
  141. docker_service_status_changed: start_result | changed
  142. - meta: flush_handlers