---
- name: Dependencies installed
  community.general.pkgng:
    name: "py27-pip"
    state: latest

- name: Pip link workaround setup
  file:
    src: /usr/local/bin/pip-2.7
    dest: /usr/local/bin/pip
    state: link

- name: SSH key installed
  template:
    src: sshkey.j2
    dest: /root/.ssh/id_ed25519
    mode: 0400

- name: Environment file installed
  template:
    src: envrc.j2
    dest: /usr/local/src/pbp_com/.envrc
    owner: root
    mode: 0600

- name: PBP source deployed
  git:
    repo: "https://git.unbl.ink/secstate/pbp_com.git"
    dest: /usr/local/src/
    update: yes
    force: yes

- name: Requirements up to date
  pip:
    requirements: /usr/local/src/pbp_com/requirements.txt
    executable: pip

- name: PBP migrations up to date
  command: bash -lc "direnv exec /usr/local/src/pbp_com /usr/local/bin/python2.7 /usr/local/src/pbp_com/manage.py migrate"
  tags:
    - deploy

- name: Supervisor file installed
  template:
    src: supervisor.conf
    dest: /usr/local/etc/supervisor/conf.d/pbp.conf
    owner: root
    mode: 0644
  notify: Supervisor restarted
