- name: Back up originals then download firmware (for RPi internal WiFi)
  include_tasks: download.yml
  when: firmware_downloaded is undefined    # SEE ALSO firmware_installed below

- name: 'Install from template: check-firmware.service, iiab-check-firmware & fw_warn.sh'
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    mode: "{{ item.mode }}"
  with_items:
    - { src: 'check-firmware.service', dest: '/etc/systemd/system/', mode: '0644' }
    - { src: 'iiab-check-firmware', dest: '/usr/sbin/', mode: '0755' }
    - { src: 'fw_warn.sh', dest: '/etc/profile.d/', mode: '0644' }

- name: Enable & (Re)Start check-firmware.service (also runs on each boot)
  systemd:
    name: check-firmware.service
    daemon_reload: yes
    state: restarted
    enabled: yes


# RECORD firmware AS INSTALLED

- name: "Set 'firmware_installed: True'"
  set_fact:
    firmware_installed: True

- name: "Add 'firmware_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^firmware_installed'
    line: 'firmware_installed: True'

# SEE ALSO firmware_downloaded above & in download.yml
