---

- hosts: etcd_servers
  become: true
  gather_facts: no
  tasks:

  - name: install etcd_servers packages
    apt:
      name:
        - etcd-server
        - curl
        - iputils-ping
        - jq
      state: present
      update_cache: false

  - name: stop etcd service
    service:
      name: etcd
      state: stopped

  - name: configure etcd
    template:
      src: setup_etcd_servers.j2
      dest: /etc/default/etcd

  - name: Cleanup etcd package's default database
    file:
      path: /var/lib/etcd/default
      state: absent

  - name: start etcd service
    service:
      name: etcd
      state: started
      enabled: true
