- name: Install apt package dependencies
  apt:
    pkg:
      - python3
      - python3-pip
      - i2c-tools
      - python3-smbus
    state: present

- name: Install setuptools
  pip:
    name: setuptools
    executable: pip3

- name: Install bme280
  pip:
    name: bme280
    executable: pip3

- name: Solve python template to read sensor
  template:
    src: read_bme280.j2
    dest: /usr/local/bin/custom_read_bme280.py

- name: Set sensor permission script path
  set_fact:
    set_olimex_sensor_permission_path: /usr/bin/olimex-sensor-set-sensor-permission

- name: Move script to grant access to sensor to file path
  template:
    src: olimex-sensor-set-sensor-permission.j2
    dest: "{{ set_olimex_sensor_permission_path }}"
    mode: 755

- name: Include olimex-sensor-set-sensor-permission at reboot on cron
  cron: name="Set permission on reboot" special_time=reboot job="sleep 30 && {{ set_olimex_sensor_permission_path }}"

- name: Run olimex-sensor-set-sensor-permission
  shell: "{{ set_olimex_sensor_permission_path }}"
