# ---------------------------------------------------------------------------- #
## \author Sebastien Beaugrand
## \sa http://beaugrand.chez.com/
## \copyright CeCILL 2.1 Free Software license
# ---------------------------------------------------------------------------- #
---
- name: install sbuild packages
  apt:
    cache_valid_time: 36000
    install_recommends: no
    name:
      - sbuild
      - mmdebstrap
      - uidmap
      - binfmt-support
      - qemu-user-static
      - arch-test
  become: yes

- name: add user to the sbuild group
  user:
    append: yes
    name: "{{ user }}"
    groups: sbuild
  become: yes

- name: mkdir /etc/qemu-binfmt
  file:
    dest: /etc/qemu-binfmt
    state: directory
  become: yes

- name: find arm sysroot
  find:
    paths: /vagrant/.vagrant
    patterns: 'arm-linux-gnueabihf*'
    file_type: directory
  register: output

- name: qemu-binfmt arm link
  file:
    src: "{{ item.path }}"
    dest: /etc/qemu-binfmt/arm
    state: link
  with_items: "{{ output.files }}"
  become: yes

- name: find aarch64 sysroot
  find:
    paths: /vagrant/.vagrant
    patterns: 'aarch64-linux-gnu*'
    file_type: directory
  register: output

- name: qemu-binfmt aarch64 link
  file:
    src: "{{ item.path }}"
    dest: /etc/qemu-binfmt/aarch64
    state: link
  with_items: "{{ output.files }}"
  become: yes