---
- name: Unarchive base OS
  hosts: build_host:&os
  tags: create_base
  vars_files:
    - ../vars/ubuntu_14_04.yml
    - ../vars/imaging_server_os.yml
  roles:
    - { role: create_loop_device, tags: create_loop_device }
    - { role: mount_loop, tags: mount_loop }
    - { role: unarchive_base, tags: unarchive_base }
    - { role: setup_chroot, tags: setup_chroot }

- name: Configuration common to all Zoox machine roles
  hosts: chroot:live:&os
  vars_files:
    - ../vars/ubuntu_14_04.yml
    - ../vars/imaging_app.yml
    - ../vars/imaging_server_os.yml
  roles:
    - { role: zoox_user, tags: zoox_user }
    - { role: zoox_directories, tags: zoox_directories }
    - { role: directories_imaging_server, tags: directories_imaging_server }
    - { role: apt_sources, tags: apt_sources }
    - { role: ubuntu_desktop, tags: ubuntu_desktop }  # Almost none of this is actually necessary for imaging machines.
    - { role: auditd, tags: auditd }
    - { role: ssh_dpkg_reconfigure, tags: ssh_dpkg_reconfigure, when: not is_live_update }  # no live updates because this removes ssh host keys, which should be present in config layer
    - { role: secure_sshd, tags: secure_sshd }
    - { role: system_tools, tags: system_tools }
    - { role: zoox_kernel, tags: zoox_kernel, when: not is_live_update }  # No live updates because the kernel is only loaded from the OS layer
    - { role: grub, tags: grub, when: not is_live_update }  # No live updates because grub is only loaded from the OS layer
    - { role: fail_safe, tags: fail_safe }
    - { role: compilers, tags: compilers }  # Only because python-dbus requires something here
    - { role: bazel, tags: bazel }
    - { role: python, tags: python }
    - { role: python_pip, tags: python_pip }
    - { role: python_pip_conf, tags: python_pip_conf }
    - { role: python_deps, tags: python_deps }
    - { role: sudo, tags: sudo }
    - { role: timezone, tags: timezone }
    - { role: utilities, tags: utilities }
    - { role: vault_client, tags: vault_client }
    - { role: overlayfs, tags: overlayfs }
    - { role: os, tags: os }  # TODO: modifies things under /sys
    - { role: disk_imaging_server, tags: disk_imaging_server }
    - { role: network_imaging_server, tags: network_imaging_server }
    - { role: packages_imaging_server, tags: packages_imaging_server }
    - { role: services_imaging_server, tags: services_imaging_server }
    - { role: zimage, tags: zimage }
    - { role: install_os_reset_script, tags: install_os_reset_script }
    - { role: zoox_os_build_metadata, asset_type: os, tags: zoox_os_build_metadata, when: not is_live_update }
    - { role: vpnc, tags: vpnc }


- name: Finalize image
  hosts: build_host:&os
  tags: finish_build
  vars_files:
    - ../vars/ubuntu_14_04.yml
    - ../vars/imaging_server_os.yml
  roles:
    - { role: teardown_chroot, tags: teardown_chroot }
    - { role: unmount_loop, tags: unmount_loop }
    - { role: gzip_image, tags: gzip_image }
