---
- hosts: build
  roles:
    - { role: build-securedrop-app-code-deb-pkg, tags: [ "app-deb" ] }
    - { role: build-generic-pkg, tags: ["securedrop-ossec-server"], package_name: "securedrop-ossec-server" }
    - { role: build-generic-pkg, tags: ["securedrop-ossec-agent"], package_name: "securedrop-ossec-agent" }
    - { role: build-generic-pkg, tags: ["securedrop-keyring"], package_name: "securedrop-keyring" }

  sudo: yes

---
- hosts: build
- name: Ensure Build VM is available.
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - name: Check for "build" machine in inventory.
      fail:
        msg: >
          The "build" VM is not reachable, but is required for
          building the app code Debian packages on the staging machines.
          Run `vagrant up build`, then `vagrant provision /staging/`.
          Thereafter you can run `vagrant provision /staging/` again
          and the application code will be rebuilt and reinstalled on each run.
      when: "'build' not in groups.all"

- name: Build securedrop-app-code deb package from local code.
  hosts: build
  vars_files:
    # The order of these files files is important, since each successive
    # include overrides vars in the previous files. Ordinarily we'd
    # use group memberships to manage the variable resolution order, but
    # since we're using Vagrant with Ansible, group management becomes tricky.
    - group_vars/securedrop.yml
    - group_vars/securedrop_application_server.yml
    - group_vars/development.yml
  roles:
    - { role: build-securedrop-app-code-deb-pkg, tags: [ "app-deb" ] }
    - { role: build-generic-pkg, tags: ["securedrop-ossec-server"], package_name: "securedrop-ossec-server" }
    - { role: build-generic-pkg, tags: ["securedrop-ossec-agent"], package_name: "securedrop-ossec-agent" }
    - { role: build-generic-pkg, tags: ["securedrop-keyring"], package_name: "securedrop-keyring" }

  sudo: yes

Check for Build VM prior to running staging playbook
Check for Build VM prior to running staging playbook

The staging playbook requires the Build VM to repacked the application
code, which is installed via the `install-local-packages` role. If the
Build VM is not running, fail and print a helpful message explaining how
to rectify the situation.
