- name: Check if Docker is installed
  command: rpm -q docker
  register: pkg_check
  failed_when: pkg_check.rc > 1
  changed_when: no

- name: Upgrade Docker
  command: "{{ ansible_pkg_mgr}} update -y docker"
  when: pkg_check.rc == 0 and g_docker_version.curr_version | version_compare('1.9','<')
  register: docker_upgrade

- name: Restart Docker
  service: name=docker state=restarted
  when: docker_upgrade | changed

- name: Check if Docker is installed
  command: rpm -q docker
  register: pkg_check
  failed_when: pkg_check.rc > 1
  changed_when: no

- name: Upgrade Docker
  command: "{{ ansible_pkg_mgr}} update -y docker"
  when: pkg_check.rc == 0 and g_docker_version.curr_version | version_compare('1.9','<')
  register: docker_upgrade

- name: Restart Docker
  command: systemctl restart docker
  when: docker_upgrade | changed


Use systemctl restart docker instead of ansible service.
Use systemctl restart docker instead of ansible service.

Ansible is doing a full service stop and then start, which does not
allow systemd to keep the containerized services up and running.
Switching to this will cause the related services to come back within a
few seconds.
