main.yml 5.1 KB

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