---

- name: Install needed tools
  package: name={{ consul_tpl_packages }}
  tags: consul,vault

- when: consul_tpl_install_mode != 'none'
  block:
    - name: Download consul_tpl
      get_url:
        url: "{{ consul_tpl_archive_url }}"
        dest: "{{ consul_tpl_root_dir }}/tmp"
        checksum: sha256:{{ consul_tpl_archive_sha256 }}
        mode: 755

    - name: Extract the archive
      unarchive:
        src: "{{ consul_tpl_root_dir }}/tmp/consul-template_{{ consul_tpl_version }}_linux_amd64.zip"
        dest: "{{ consul_tpl_root_dir }}/tmp"
        remote_src: True

    - name: Install consul_tpl binary
      copy:
        src: "{{ consul_tpl_root_dir }}/tmp/consul-template"
        dest: "{{ consul_tpl_root_dir }}/bin/consul-template"
        remote_src: True
        mode: 755

    - name: Link in /usr/local/bin
      file: src={{ consul_tpl_root_dir }}/bin/consul-template dest=/usr/local/bin/consul-template state=link force=True
  tags: consul,vault

