main.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ---
  2. # tasks file for docker
  3. - name: Get current installed version if docker_version is specified
  4. command: "{{ repoquery_cmd }} --installed --qf '%{version}' docker"
  5. when: not openshift.common.is_atomic | bool and docker_version != ''
  6. register: docker_version_result
  7. changed_when: false
  8. - stat: path=/etc/sysconfig/docker-storage
  9. register: docker_storage_check
  10. - name: Remove deferred deletion for downgrades from 1.9
  11. command: >
  12. sed -i 's/--storage-opt dm.use_deferred_deletion=true//' /etc/sysconfig/docker-storage
  13. when: docker_storage_check.stat.exists | bool and not docker_version_result | skipped and docker_version_result.stdout | default('0.0', True) | version_compare('1.9', '>=') and docker_version | version_compare('1.9', '<')
  14. - name: Downgrade docker if necessary
  15. command: "{{ ansible_pkg_mgr }} downgrade -y docker-{{ docker_version }}"
  16. register: docker_downgrade_result
  17. when: not docker_version_result | skipped and docker_version_result.stdout | default('0.0', True) | version_compare(docker_version, 'gt')
  18. - name: Install docker
  19. action: "{{ ansible_pkg_mgr }} name=docker{{ '-' + docker_version if docker_version is defined and docker_version != '' else '' }} state=present"
  20. when: not openshift.common.is_atomic | bool and docker_downgrade_result | skipped
  21. # If docker were enabled and started before we downgraded it may have entered a
  22. # failed state. Check for that and clear it if necessary.
  23. - name: Check that docker hasn't entered failed state
  24. command: systemctl show docker
  25. register: docker_state
  26. changed_when: False
  27. - name: Reset docker service state
  28. command: systemctl reset-failed docker.service
  29. when: " 'ActiveState=failed' in docker_state.stdout "
  30. - name: Start the docker service
  31. service:
  32. name: docker
  33. enabled: yes
  34. state: started
  35. register: start_result
  36. - set_fact:
  37. docker_service_status_changed: start_result | changed
  38. - include: udev_workaround.yml
  39. when: docker_udev_workaround | default(False) | bool
  40. - stat: path=/etc/sysconfig/docker
  41. register: docker_check
  42. - name: Set registry params
  43. lineinfile:
  44. dest: /etc/sysconfig/docker
  45. regexp: '^{{ item.reg_conf_var }}=.*$'
  46. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val | oo_prepend_strings_in_list(item.reg_flag ~ ' ') | join(' ') }}'"
  47. when: item.reg_fact_val != '' and docker_check.stat.isreg
  48. with_items:
  49. - reg_conf_var: ADD_REGISTRY
  50. reg_fact_val: "{{ docker_additional_registries | default(None, true)}}"
  51. reg_flag: --add-registry
  52. - reg_conf_var: BLOCK_REGISTRY
  53. reg_fact_val: "{{ docker_blocked_registries| default(None, true) }}"
  54. reg_flag: --block-registry
  55. - reg_conf_var: INSECURE_REGISTRY
  56. reg_fact_val: "{{ docker_insecure_registries| default(None, true) }}"
  57. reg_flag: --insecure-registry
  58. notify:
  59. - restart docker
  60. - name: Set Proxy Settings
  61. lineinfile:
  62. dest: /etc/sysconfig/docker
  63. regexp: '^{{ item.reg_conf_var }}=.*$'
  64. line: "{{ item.reg_conf_var }}='{{ item.reg_fact_val }}'"
  65. with_items:
  66. - reg_conf_var: HTTP_PROXY
  67. reg_fact_val: "{{ docker_http_proxy | default('') }}"
  68. - reg_conf_var: HTTPS_PROXY
  69. reg_fact_val: "{{ docker_https_proxy | default('') }}"
  70. - reg_conf_var: NO_PROXY
  71. reg_fact_val: "{{ docker_no_proxy | default('') | join(',') }}"
  72. notify:
  73. - restart docker
  74. - name: Set various docker options
  75. lineinfile:
  76. dest: /etc/sysconfig/docker
  77. regexp: '^OPTIONS=.*$'
  78. line: "OPTIONS='\
  79. {% if ansible_selinux and ansible_selinux.status == '''enabled''' %} --selinux-enabled{% endif %}\
  80. {% if docker_log_driver is defined %} --log-driver {{ docker_log_driver }}{% endif %}\
  81. {% if docker_log_options is defined %} {{ docker_log_options | oo_split() | oo_prepend_strings_in_list('--log-opt ') | join(' ')}}{% endif %}\
  82. {% if docker_options is defined %} {{ docker_options }}{% endif %}\
  83. {% if docker_disable_push_dockerhub is defined %} --confirm-def-push={{ docker_disable_push_dockerhub | bool }}{% endif %}'"
  84. when: docker_check.stat.isreg
  85. notify:
  86. - restart docker
  87. - meta: flush_handlers