---
# TODO: work out nftables firewall rules (should be on upstream)
- name: waydroid | Install waydroid
  apk:
    name: waydroid
    state: present

- name: waydroid | Check whether base image is downloaded
  stat:
    path: /var/lib/waydroid/image/system.img
  register: waydroid_image_check

- name: waydroid | Download base image and initialize
  command: 'waydroid init -s {{ waydroid.system_type }} -r {{ waydroid.rom_type }}'
  when: not waydroid_image_check.exists

- name: waydroid | Add apparmor rules
  blockinfile:
    block: |
      @{run}/waydroid-lxc/ r,
      @{run}/waydroid-lxc/* rw,
    marker: '# {mark} WAYDROID BLOCK'
    path: /etc/apparmor.d/local/usr.sbin.dnsmasq

- name: waydroid | Start container service on runlevel 'default'
  service:
    name: waydroid-container
    runlevel: default
    state: started
    enabled: yes
