---
- name: Get currently-deployed etcd version
  shell: "{{ docker_bin_dir }}/docker ps --filter='name={{ etcd_member_name }}' --format='{{ '{{ .Image }}' }}'"
  register: etcd_current_docker_image
  when: etcd_cluster_setup

- name: Get currently-deployed etcd-events version
  shell: "{{ docker_bin_dir }}/docker ps --filter='name={{ etcd_member_name }}-events' --format='{{ '{{ .Image }}' }}'"
  register: etcd_events_current_docker_image
  when: etcd_events_cluster_setup

- name: Restart etcd if necessary
  command: /bin/true
  notify: Restart etcd
  when:
    - etcd_cluster_setup
    - etcd_image_tag not in etcd_current_docker_image.stdout | default('')

- name: Restart etcd-events if necessary
  command: /bin/true
  notify: Restart etcd-events
  when:
    - etcd_events_cluster_setup
    - etcd_image_tag not in etcd_events_current_docker_image.stdout | default('')

- name: Install etcd launch script
  template:
    src: etcd.j2
    dest: "{{ bin_dir }}/etcd"
    owner: 'root'
    mode: "0750"
    backup: true
  when: etcd_cluster_setup

- name: Install etcd-events launch script
  template:
    src: etcd-events.j2
    dest: "{{ bin_dir }}/etcd-events"
    owner: 'root'
    mode: "0750"
    backup: true
  when: etcd_events_cluster_setup
