---
# Set some facts to reference from hostvars
- import_tasks: set_facts.yml

- name: Add new etcd members to cluster
  command: >
    {{ r_etcd_common_etcdctl_command }}
                     --cert-file {{ etcd_peer_cert_file }}
                     --key-file {{ etcd_peer_key_file }}
                     --ca-file {{ etcd_peer_ca_file }}
                     -C {{ etcd_peer_url_scheme }}://{{ hostvars[etcd_ca_host].etcd_ip }}:{{ etcd_client_port }}
                     member add {{ etcd_hostname }} {{ etcd_peer_url_scheme }}://{{ etcd_ip }}:{{ etcd_peer_port }}
  delegate_to: "{{ etcd_ca_host }}"
  failed_when:
  - etcd_add_check.rc == 1
  - ("peerURL exists" not in etcd_add_check.stderr)
  register: etcd_add_check
  retries: 3
  delay: 10
  until: etcd_add_check.rc == 0
