---
# INPUT r_etcd_upgrade_version?

# F23 GA'd with etcd 2.0, currently has 2.2 in updates
# F24 GA'd with etcd-2.2, currently has 2.2 in updates
# F25 Beta currently has etcd 3.0
# RHEL 7.3.4 with etcd-3.1.3-1.el7
# RHEL 7.3.3 with etcd-3.1.0-2.el7
# RHEL 7.3.2 with etcd-3.0.15-1.el7

- name: Verify cluster is healthy pre-upgrade
  command: "{{ etcdctlv2 }} cluster-health"

- set_fact:
    l_etcd_target_package: "{{ 'etcd' if r_etcd_upgrade_version is not defined else 'etcd-'+r_etcd_upgrade_version+'*' }}"

- name: Update etcd RPM to {{ l_etcd_target_package }}
  package:
    name: "{{ l_etcd_target_package }}"
    state: latest

- lineinfile:
    destfile: "{{ etcd_conf_file }}"
    regexp: '^ETCD_QUOTA_BACKEND_BYTES='
    line: "ETCD_QUOTA_BACKEND_BYTES={{ etcd_quota_backend_bytes }}"

- name: Restart etcd
  service:
    name: "{{ etcd_service }}"
    state: restarted

- name: Verify cluster is healthy
  command: "{{ etcdctlv2 }} cluster-health"
  register: etcdctl
  until: etcdctl.rc == 0
  retries: 3
  delay: 10
