main.yml 4.4 KB

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