---
version: '3'

vars:
  ANSIBLE_VENV:
    sh: echo "$HOME/.local/megabytelabs/ansible"

tasks:
  install:ansible:
    cmds:
      - pip3 install ansible

  main:
    deps:
      - install:ansible
    cmds:
      - task: requirements

  requirements:
    deps:
      - requirements:galaxy
      - requirements:python

  requirements:galaxy:
    cmds:
      - |
        PATH="$PATH:$HOME/.local/bin"
        ansible-galaxy install -r requirements.yml
    status:
      - '[ ! -f requirements.yml ]'

  requirements:python:
    cmds:
      - pip3 install requirements.txt
    status:
      - '[ ! -f requirements.txt ]'

  role:
    deps:
      - :install:software:docker
    desc: Install an Ansible role by using Docker
    summary: |
      # Install an Ansible Role

      This task installs a single Ansible role on the localhost. It
      will download the role from Ansible Galaxy and then provision
      the localhost using a Docker container (so that Ansible dependencies
      are not permanently installed).

      **Example:**
      `task install:ansible:role -- professormanhattan/androidstudio
    cmds:
      - |
        if [ -d ~/.ansible/roles/{{.CLI_ARGS}} ]; then
          rm -rf ~/.ansible/roles/{{.CLI_ARGS}}
        fi
      - ansible-galaxy install --force --ignore-errors professormanhattan.androidstudio
      - echo "TODO - run Docker and provision"

  start:
    deps:
      - :install:software:python
    cmds:
      - python3 -m venv {{.ANSIBLE_VENV}}
      - |
        source {{.ANSIBLE_VENV}}/bin/activate
        task install:ansible:main