---
- name: Flannel | delete default docker bridge
  command: ip link delete docker0
  failed_when: false
  notify: Flannel | restart docker

- name: Flannel | delete flannel interface
  command: ip link delete flannel.1
  failed_when: false

# special cases for atomic because it defaults to live-restore: true
# So we disable live-restore to pickup the new flannel IP.  After
# we enable it, we have to restart docker again to pickup the new
# setting and restore the original behavior
- name: Flannel | restart docker
  command: /bin/true
  notify:
    - Flannel | reload systemd
    - Flannel | reload docker.socket
    - Flannel | configure docker live-restore true (atomic)
    - Flannel | reload docker
    - Flannel | pause while Docker restarts
    - Flannel | wait for docker

- name: Flannel | reload systemd
  shell: systemctl daemon-reload

- name: Flannel | reload docker.socket
  service:
    name: docker.socket
    state: restarted
  when: ansible_os_family in ['CoreOS', 'Container Linux by CoreOS']

- name: Flannel | configure docker live-restore true (atomic)
  replace:
    name: /etc/docker/daemon.json
    regexp: '"live-restore":.*true'
    replace: '"live-restore": false'
  when: is_atomic

- name: Flannel | reload docker
  service:
    name: docker
    state: restarted

- name: Flannel | pause while Docker restarts
  pause:
    seconds: 10
    prompt: "Waiting for docker restart"

- name: Flannel | wait for docker
  command: "{{ docker_bin_dir }}/docker images"
  register: docker_ready
  retries: 10
  delay: 5
  until: docker_ready.rc == 0

- name: Flannel | reload kubelet
  service:
    name: kubelet
    state: restarted