---
- name: Unarchive base OS
  hosts: build_host:&os
  tags: create_base
  vars_files:
    - ../vars/ubuntu_20_04.yml
    - ../vars/operator_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: Build operator OS
  hosts: chroot:live:&os
  vars_files:
    - ../vars/ubuntu_20_04.yml
    - ../vars/imaging_app.yml
    - ../vars/operator_os.yml
  roles:
    - { role: apt_sources, tags: apt_sources }
    - { role: zoox_user, tags: zoox_user }
    # - { role: can_isotp, tags: can_isotp } # Broken for Ubuntu 20.04: https://jira.zooxlabs.com/browse/FW-11265
    - { role: ubuntu_desktop, tags: ubuntu_desktop }
    - { role: configure_focal_desktop, tags: configure_focal_desktop }
    - { role: secure_sshd, tags: secure_sshd }
    - { 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: fsck, tags: fsck }
    - { role: git_lfs, tags: git_lfs }
    - { role: grub, tags: grub, when: not is_live_update }  # No live updates because grub is only loaded from the OS layer
    - { role: nvidia_440_focal, tags: nvidia_440_focal }
    - { role: pair_with_robot, tags: pair_with_robot }
    - { 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: vpnc, tags: vpnc }
    - { role: bazel, tags: bazel }
    - { role: overlayfs, tags: overlayfs, when: not is_live_update }
    - { role: os, tags: os }
    - { role: rc, tags: rc }
    - { role: rc_local, tags: rc_local }
    - { role: iperf3, tags: iperf3 }
    - { role: focal_standalone_networking, tags: focal_standalone_networking }
    - { role: operator_laptop_disks, tags: operator_laptop_disks }
    - { role: operator_laptop_config, tags: operator_laptop_config } # Depends on rc role
    - { role: os_update_check, tags: os_update_check }
    - { role: vscode, tags: vscode }
    - { role: zoox_directories, tags: zoox_directories }
    - { role: machine_role, tags: machine_role }
    - { role: ubuntu_kernel, tags: ubuntu_kernel, when: not is_live_update }  # No live updates because the kernel is only loaded from the OS layer
    - { role: zaccess, tags: zaccess }
    - { role: zoox_pki, tags: zoox_pki }
    - { role: zstart_stub, tags: zstart_stub }
    - { 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 }  # no live updates because this file represents the state of the OS layer.


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