---
- name: Dependencies installed
  community.general.pkgng:
    name: git-tiny,go
    state: latest
  tags:
    - build

- name: Source folder exists
  file: path=/usr/local/src mode=0755 state=directory
  tags:
    - build

- name: Podgrab source deployed
  git:
    repo: "https://github.com/akhilrex/podgrab.git"
    dest: /usr/local/src/podgrab
    force: yes
    accept_hostkey: yes
    update: yes
  tags:
    - build

- name: Patch podgrab for jails
  shell:
    cmd: 'sed -i -e ''s/client\/*/\/usr\/local\/src\/podgrab\/client\//'' /usr/local/src/podgrab/main.go'
    warn: false
  tags:
    - build

- name: Podgrab binary built
  shell:
    chdir: /usr/local/src/podgrab
    cmd: go get github.com/mattn/go-isatty@v0.0.12 && go build .

- name: Install podgrab
  ansible.builtin.copy:
    src: /usr/local/src/podgrab/podgrab
    dest: /usr/local/bin/podgrab
    remote_src: yes
    mode: a+x
  notify: Podgrab restarted

- name: Podgrab assets and config moved
  shell:
    cmd: mkdir -p /var/podgrab/config && cp -r /usr/local/src/podgrab/webassets /var/podgrab/ && cp -r /usr/local/src/podgrab/client /var/podgrab/
  tags:
    - build

- name: Podgrab rc file installed
  ansible.builtin.copy:
    src: podgrab.rc
    dest: /usr/local/etc/rc.d/podgrab
    mode: a+x
  notify: Podgrab restarted
