main.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. ---
  2. - name: Get current installed Docker version
  3. command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
  4. when: not openshift.common.is_atomic | bool
  5. register: curr_docker_version
  6. changed_when: false
  7. - name: Error out if Docker pre-installed but too old
  8. fail:
  9. msg: "Docker {{ curr_docker_version.stdout }} is installed, but >= 1.9.1 is required."
  10. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and curr_docker_version.stdout | version_compare('1.9.1', '<') and not docker_version is defined
  11. - name: Error out if requested Docker is too old
  12. fail:
  13. msg: "Docker {{ docker_version }} requested, but >= 1.9.1 is required."
  14. when: docker_version is defined and docker_version | version_compare('1.9.1', '<')
  15. - name: Get latest available version of Docker
  16. command: >
  17. {{ repoquery_cmd }} --qf '%{version}' "docker"
  18. register: avail_docker_version
  19. failed_when: false
  20. changed_when: false
  21. when: docker_version is defined and not openshift.common.is_atomic | bool
  22. # If a docker_version was requested, sanity check that we can install or upgrade to it, and
  23. # no downgrade is required.
  24. - name: Fail if Docker version requested but downgrade is required
  25. fail:
  26. msg: "Docker {{ curr_docker_version.stdout }} is installed, but version {{ docker_version }} was requested."
  27. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and docker_version is defined and curr_docker_version.stdout | version_compare(docker_version, '>')
  28. # This involves an extremely slow migration process, users should instead run the
  29. # Docker 1.10 upgrade playbook to accomplish this.
  30. - name: Error out if attempting to upgrade Docker across the 1.10 boundary
  31. fail:
  32. msg: "Cannot upgrade Docker to >= 1.10, please upgrade or remove Docker manually, or use the Docker upgrade playbook if OpenShift is already installed."
  33. when: not curr_docker_version | skipped and curr_docker_version.stdout != '' and curr_docker_version.stdout | version_compare('1.10', '<') and docker_version is defined and docker_version | version_compare('1.10', '>=')
  34. # Make sure Docker is installed, but does not update a running version.
  35. # Docker upgrades are handled by a separate playbook.
  36. - name: Install Docker
  37. package: name=docker{{ '-' + docker_version if docker_version is defined else '' }} state=present
  38. when: not openshift.common.is_atomic | bool
  39. - name: Ensure docker.service.d directory exists
  40. file:
  41. path: "{{ docker_systemd_dir }}"
  42. state: directory
  43. # Extend the default Docker service unit file
  44. - name: Configure Docker service unit file
  45. template:
  46. dest: "{{ docker_systemd_dir }}/custom.conf"
  47. src: custom.conf.j2
  48. - include: udev_workaround.yml
  49. when: docker_udev_workaround | default(False) | bool
  50. - stat: path=/etc/sysconfig/docker
  51. register: docker_check
  52. - name: Set registry params
  53. lineinfile:
  54. dest: /etc/sysconfig/docker
  55. regexp: '^{{ item.reg_conf_var }}=.*$'
  56. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  57. when: item.reg_fact_val != '' and docker_check.stat.isreg is defined and docker_check.stat.isreg
  58. with_items:
  59. - reg_conf_var: ADD_REGISTRY
  60. reg_fact_val: "{{ docker_additional_registries | default(None, true)}}"
  61. reg_flag: --add-registry
  62. - reg_conf_var: BLOCK_REGISTRY
  63. reg_fact_val: "{{ docker_blocked_registries| default(None, true) }}"
  64. reg_flag: --block-registry
  65. - reg_conf_var: INSECURE_REGISTRY
  66. reg_fact_val: "{{ docker_insecure_registries| default(None, true) }}"
  67. reg_flag: --insecure-registry
  68. notify:
  69. - restart docker
  70. - name: Set Proxy Settings
  71. lineinfile:
  72. dest: /etc/sysconfig/docker
  73. regexp: '^{{ item.reg_conf_var }}=.*$'
  74. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  75. state: "{{ 'present' if item.reg_fact_val != '' else 'absent'}}"
  76. with_items:
  77. - reg_conf_var: HTTP_PROXY
  78. reg_fact_val: "{{ docker_http_proxy | default('') }}"
  79. - reg_conf_var: HTTPS_PROXY
  80. reg_fact_val: "{{ docker_https_proxy | default('') }}"
  81. - reg_conf_var: NO_PROXY
  82. reg_fact_val: "{{ docker_no_proxy | default('') | join(',') }}"
  83. notify:
  84. - restart docker
  85. when:
  86. - docker_check.stat.isreg is defined and docker_check.stat.isreg and '"http_proxy" in openshift.common or "https_proxy" in openshift.common'
  87. - name: Set various Docker options
  88. lineinfile:
  89. dest: /etc/sysconfig/docker
  90. regexp: '^OPTIONS=.*$'
  91. line: "OPTIONS='\
  92. {% if ansible_selinux and ansible_selinux.status == '''enabled''' %} --selinux-enabled{% endif %}\
  93. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %}\
  94. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %}\
  95. {% if docker_options is defined %} {{ docker_options }}{% endif %}\
  96. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %}'"
  97. when: docker_check.stat.isreg is defined and docker_check.stat.isreg
  98. notify:
  99. - restart docker
  100. - name: Start the Docker service
  101. systemd:
  102. name: docker
  103. enabled: yes
  104. state: started
  105. daemon_reload: yes
  106. register: start_result
  107. - set_fact:
  108. docker_service_status_changed: start_result | changed
  109. - meta: flush_handlers