---

- name: Install dependencies
  package: name={{ pgweb_packages }}
  tags: pgweb,pg

- when: pgweb_install_mode != 'none'
  block:
    - name: Download pgweb
      get_url:
        url: "{{ pgweb_archive_url }}"
        dest: "{{ pgweb_root_dir }}/tmp/"
        checksum: sha256:{{ pgweb_archive_sha256 }}

    - name: Extract archive
      unarchive:
        src: "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64.zip"
        dest: "{{ pgweb_root_dir }}/tmp/"
        remote_src: True

    - name: Install pgweb binary
      copy:
        src: "{{ pgweb_root_dir }}/tmp/pgweb_linux_amd64"
        dest: "{{ pgweb_root_dir }}/bin/pgweb"
        remote_src: True
        mode: 755
      notify: restart pgweb

  tags: pgweb,pg

- name: Install systemd unit
  template: src=pgweb.service.j2 dest=/etc/systemd/system/pgweb.service
  register: pgweb_unit
  notify: restart pgweb
  tags: pgweb,pg

- name: Reload systemd
  systemd: daemon_reload=True
  when: pgweb_unit.changed
  tags: pgweb,pg
