main.yml 4.4 KB

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