---
- name: Check to see if etcd client is installed
  stat:
    path: /usr/bin/etcdctl
  register: etcd_result

- name: Validate etcd
  command: "etcdctl -C https://{{ ansible_hostname if validate_etcd_short_hostname else ansible_fqdn }}:2379 --ca-file=/etc/origin/master/master.etcd-ca.crt --cert-file=/etc/origin/master/master.etcd-client.crt --key-file=/etc/origin/master/master.etcd-client.key cluster-health | grep 'cluster is'"
  register: etcd_health
  when: etcd_result.stat.exists

- name: ETCD Cluster is healthy
  debug:
    msg: "Cluster is healthy"
  when: etcd_result.stat.exists and etcd_health.stdout.find('cluster is healthy') != -1

- name: ETCD Cluster is NOT healthy
  debug:
    msg: "Cluster is NOT healthy"
  when: etcd_result.stat.exists and etcd_health.stdout.find('cluster is healthy') == -1
