main.yml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. ---
  2. # tasks file for docker
  3. # Avoid docker 1.9 when installing origin < 1.2 or OSE < 3.2 on RHEL/Centos and
  4. # See: https://bugzilla.redhat.com/show_bug.cgi?id=1304038
  5. - name: Default to latest docker for 1.2/3.2 or Fedora
  6. set_fact:
  7. docker_version: ''
  8. when: openshift.common.version_gte_3_2_or_1_2 | bool or ansible_distribution == 'Fedora'
  9. - name: Gather latest version of docker
  10. shell: >
  11. yum list available -e 0 -q "docker" 2>&1 | tail -n +2 | awk '{ print $2 }' | sort -r | tr '\n' ' ' | tail -n 1
  12. register: latest_docker
  13. when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
  14. - name: Check if Docker 1.9 is the latest
  15. set_fact:
  16. docker19_is_latest: "{{ True if '1.9' in latest_docker.stdout else False }}"
  17. when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
  18. - set_fact:
  19. docker_version: "{{ '-1.8.2' if docker19_is_latest | bool else ''}}"
  20. when: not openshift.common.version_gte_3_2_or_1_2 | bool and ansible_distribution != 'Fedora'
  21. - name: Install docker
  22. action: "{{ ansible_pkg_mgr }} name=docker{{ docker_version }} state=present"
  23. when: not openshift.common.is_atomic | bool
  24. - name: enable and start the docker service
  25. service:
  26. name: docker
  27. enabled: yes
  28. state: started
  29. register: start_result
  30. - set_fact:
  31. docker_service_status_changed: start_result | changed
  32. - include: udev_workaround.yml
  33. when: docker_udev_workaround | default(False) | bool
  34. - stat: path=/etc/sysconfig/docker
  35. register: docker_check
  36. - name: Set registry params
  37. lineinfile:
  38. dest: /etc/sysconfig/docker
  39. regexp: '^{{ item.reg_conf_var }}=.*$'
  40. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  41. when: item.reg_fact_val is defined and docker_check.stat.isreg
  42. with_items:
  43. - reg_conf_var: ADD_REGISTRY
  44. reg_fact_val: "{{ docker_additional_registries }}"
  45. reg_flag: --add-registry
  46. - reg_conf_var: BLOCK_REGISTRY
  47. reg_fact_val: "{{ docker_blocked_registries }}"
  48. reg_flag: --block-registry
  49. - reg_conf_var: INSECURE_REGISTRY
  50. reg_fact_val: "{{ docker_insecure_registries }}"
  51. reg_flag: --insecure-registry
  52. notify:
  53. - restart docker
  54. - name: Set various docker options
  55. lineinfile:
  56. dest: /etc/sysconfig/docker
  57. regexp: '^OPTIONS=.*$'
  58. line: "OPTIONS='\
  59. {% if ansible_selinux and ansible_selinux.status == '''enabled''' %} --selinux-enabled{% endif %}\
  60. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %}\
  61. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %}\
  62. {% if docker_options is defined %} {{ docker_options }}{% endif %}\
  63. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %}'"
  64. when: docker_check.stat.isreg
  65. notify:
  66. - restart docker
  67. - meta: flush_handlers