systemcontainer_docker.yml 5.6 KB

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