---
# Installs can-isotp.deb
- block:
  # The following dependencies are need to install the ISO-TP driver
  - name: Install CAN ISO-TP module dependencies
    apt:
      name:
        - "dkms"
      install_recommends: no
      cache_valid_time: "{{ apt_cache_valid_time }}"

  - name: Create stub directory
    file:
      path: /stubs
      state: directory
    # This role is run by the dev setup script which does not set `is_live_update`
    when: not (is_live_update | default(True))

  - name: Create stubs for modprobe and rmmod
    file:
      path: "/stubs/{{ item }}"
      state: link
      src: "/bin/true"
    with_items:
      - modprobe
      - rmmod
    when: not (is_live_update | default(True))

  - name: Install CAN ISO-TP module
    http_deb:
      name: "can-isotp"
      version: "{{ can_isotp_version }}"
      url: "{{ can_isotp_download_url }}"
      checksum: "sha256:{{ can_isotp_sha }}"
    environment:
      # Make modprobe and rmmod resolve to /bin/true
      PATH: "/stubs:{{ ansible_env.PATH }}"

  - name: Remove stubs directory
    file:
      path: /stubs
      state: absent
    when: not (is_live_update | default(True))

  become: yes
