docker_upgrade.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. - name: Check for appropriate Docker versions for 1.9.x to 1.10.x upgrade
  2. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config
  3. roles:
  4. - openshift_facts
  5. tasks:
  6. - fail:
  7. msg: Cannot upgrade Docker on Atomic operating systems.
  8. when: openshift.common.is_atomic | bool
  9. - name: Determine available Docker version
  10. script: ../../../../common/openshift-cluster/upgrades/files/rpm_versions.sh docker
  11. register: g_docker_version_result
  12. - name: Check if Docker is installed
  13. command: rpm -q docker
  14. register: pkg_check
  15. failed_when: pkg_check.rc > 1
  16. changed_when: no
  17. - set_fact:
  18. g_docker_version: "{{ g_docker_version_result.stdout | from_yaml }}"
  19. - name: Set fact if docker requires an upgrade
  20. set_fact:
  21. docker_upgrade: true
  22. when: pkg_check.rc == 0 and g_docker_version.curr_version | version_compare('1.10','<')
  23. - fail:
  24. msg: This playbook requires access to Docker 1.10 or later
  25. when: g_docker_version.avail_version | default(g_docker_version.curr_version, true) | version_compare('1.10','<')
  26. # If a node fails, halt everything, the admin will need to clean up and we
  27. # don't want to carry on, potentially taking out every node. The playbook can safely be re-run
  28. # and will not take any action on a node already running 1.10+.
  29. - name: Evacuate and upgrade nodes
  30. hosts: oo_masters_to_config:oo_nodes_to_config:oo_etcd_to_config
  31. serial: 1
  32. any_errors_fatal: true
  33. tasks:
  34. - debug: var=docker_upgrade
  35. - name: Prepare for Node evacuation
  36. command: >
  37. {{ openshift.common.admin_binary }} manage-node {{ openshift.common.hostname | lower }} --schedulable=false
  38. delegate_to: "{{ groups.oo_first_master.0 }}"
  39. when: docker_upgrade is defined and docker_upgrade | bool and inventory_hostname in groups.oo_nodes_to_config
  40. # TODO: skip all node evac stuff for non-nodes (i.e. separate containerized etcd hosts)
  41. - name: Evacuate Node for Kubelet upgrade
  42. command: >
  43. {{ openshift.common.admin_binary }} manage-node {{ openshift.common.hostname | lower }} --evacuate --force
  44. delegate_to: "{{ groups.oo_first_master.0 }}"
  45. when: docker_upgrade is defined and docker_upgrade | bool and inventory_hostname in groups.oo_nodes_to_config
  46. - name: Stop containerized services
  47. service: name={{ item }} state=stopped
  48. with_items:
  49. - "{{ openshift.common.service_type }}-master"
  50. - "{{ openshift.common.service_type }}-master-api"
  51. - "{{ openshift.common.service_type }}-master-controllers"
  52. - "{{ openshift.common.service_type }}-node"
  53. - etcd_container
  54. - openvswitch
  55. failed_when: false
  56. when: docker_upgrade is defined and docker_upgrade | bool and openshift.common.is_containerized | bool
  57. - name: Remove all containers and images
  58. script: files/nuke_images.sh docker
  59. register: nuke_images_result
  60. when: docker_upgrade is defined and docker_upgrade | bool
  61. - name: Upgrade Docker
  62. command: "{{ ansible_pkg_mgr}} update -y docker"
  63. register: docker_upgrade_result
  64. when: docker_upgrade is defined and docker_upgrade | bool
  65. - name: Restart containerized services
  66. service: name={{ item }} state=started
  67. with_items:
  68. - etcd_container
  69. - openvswitch
  70. - "{{ openshift.common.service_type }}-master"
  71. - "{{ openshift.common.service_type }}-master-api"
  72. - "{{ openshift.common.service_type }}-master-controllers"
  73. - "{{ openshift.common.service_type }}-node"
  74. failed_when: false
  75. when: docker_upgrade is defined and docker_upgrade | bool and openshift.common.is_containerized | bool
  76. - name: Wait for master API to come back online
  77. become: no
  78. local_action:
  79. module: wait_for
  80. host="{{ inventory_hostname }}"
  81. state=started
  82. delay=10
  83. port="{{ openshift.master.api_port }}"
  84. when: docker_upgrade is defined and docker_upgrade | bool and inventory_hostname in groups.oo_masters_to_config
  85. - name: Set node schedulability
  86. command: >
  87. {{ openshift.common.admin_binary }} manage-node {{ openshift.common.hostname | lower }} --schedulable=true
  88. delegate_to: "{{ groups.oo_first_master.0 }}"
  89. when: openshift.node.schedulable | bool
  90. when: docker_upgrade is defined and docker_upgrade | bool and inventory_hostname in groups.oo_nodes_to_config and openshift.node.schedulable | bool