# Specific to Raspberry Pi

- name: Install udev rule /etc/udev/rules.d/92-rtc-i2c.rules from template, to transfer hwclock to system clock at dev creation, if rtc_id is defined and rtc_id != "none"
  template:
    src: 92-rtc-i2c.rules
    dest: /etc/udev/rules.d/92-rtc-i2c.rules
    owner: root
    group: root
    mode: 0644
  when: rtc_id is defined and rtc_id != "none"

# RTC requires a change to the device tree (and reboot)
- name: Enable i2c-rtc device (with "dtoverlay=i2c-rtc,{{ rtc_id }}=on" in /boot/config.txt, requires reboot!) if rtc_id is defined and rtc_id != "none"
  lineinfile:
    path: /boot/config.txt
    line: "dtoverlay=i2c-rtc,{{ rtc_id }}=on"
    state: present
  register: rpiconfig    # HMMM REGISTER "rpiconfig" IS *COMPLETELY UNUSED* AS OF 2018-11-02
  when: rtc_id is defined and rtc_id != "none"

#- name: Install udev rule /etc/udev/rules.d/92-rtc-i2c.rules from template, to transfer hwclock to system clock at dev creation, if rtc_id != "none"
#  template:
#    src: 92-rtc-i2c.rules
#    dest: /etc/udev/rules.d/92-rtc-i2c.rules
#    owner: root
#    group: root
#    mode: 0644
#  when: rtc_id != "none"

- name: Install latest ntp package
  package:
    name: ntp
    state: latest

- name: Increase swap file size (to CONF_SWAPSIZE=500 in /etc/dphys-swapfile) as kalite pip download fails (debuntu)
  lineinfile:
    path: /etc/dphys-swapfile
    regexp: "^CONF_SWAPSIZE"
    line: CONF_SWAPSIZE=500
  when: is_debuntu | bool

- name: Restart swap service "dphys-swapfile" (debuntu)
  #command: /etc/init.d/dphys-swapfile restart
  service:    # A rare/legacy service that is NOT systemd
    name: dphys-swapfile
    state: restarted
  when: is_debuntu | bool

- name: Install RPi rootfs resizing (iiab-rpi-max-rootfs.sh) and its systemd service (iiab-rpi-root-resize.service), from templates
  template:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  with_items:
    - { src: 'iiab-rpi-max-rootfs.sh', dest: '/usr/sbin/iiab-rpi-max-rootfs.sh', mode: '0755'}
    - { src: 'iiab-rpi-root-resize.service', dest: '/etc/systemd/system/iiab-rpi-root-resize.service', mode: '0644'}

- name: Enable RPi rootfs resizing (systemd service iiab-rpi-root-resize.service)
  systemd:
    name: iiab-rpi-root-resize
    enabled: yes
