diff --git a/tasks/main.yaml b/tasks/main.yaml
index b775c93f308293e1b15be3dac6d3f7b66c546228..4bad2c39f1ff2bd9b6ce711c2b5088a267a15d09 100644
--- a/tasks/main.yaml
+++ b/tasks/main.yaml
@@ -1,5 +1,27 @@
---
+- name: Install required packages
+ apt:
+ name: '{{ item }}'
+ state: latest
+ update_cache: yes
+ with_items:
+ - i2c-tools
+ - python-smbus
+ become: true
+
+- name: Check if I2C interface is enabled
+ command: raspi-config nonint get_i2c
+ register: i2c_status
+ changed_when: false
+ become: true
+
+- name: Enable I2C interface
+ command: raspi-config nonint do_i2c 0
+ when: i2c_status.stdout is defined and i2c_status.stdout != '0'
+ register: enabled_i2c
+ become: true
+
# We need to make sure dtoverlay is set to any non-empty value
- name: Check if 'dtoverlay' is already set
shell: grep -E "^dtoverlay *=.+" /boot/config.txt
@@ -13,6 +35,8 @@
dest: /boot/config.txt
line: dtoverlay=i2c-rtc,ds3231
when: (check_dtoverlay.rc is defined) and (check_dtoverlay.rc == 1)
+ register: set_dtoverlay
+ become: true
# Get the existing dtoverlay value if it is set
- name: Get current 'dtoverlay' value
@@ -34,6 +58,63 @@
when: (check_dtoverlay|success)
and (dtoverlay|success)
and (dtoverlay.stdout is defined and dtoverlay.stdout != '')
+ register: updated_dtoverlay
+ become: true
+
+# Remove the fake-hwclock package so it doesn't interfere
+- name: Remove the 'fake-hwclock' package
+ apt:
+ name: fake-hwclock
+ purge: yes
+ state: absent
+ become: true
+
+#- name: Remove the 'fake-hwclock' CRON job
+# file:
+# path: /etc/cron.hourly/fake-hwclock
+# state: absent
+
+#- name: Remove the 'fake-hwclock' init script
+# command: update-rc.d -f fake-hwclock remove
+
+# Reboot host and wait for it to return
+- name: Reboot host
+ shell: sleep 1 && shutdown -r now "Ansible triggered reboot" && sleep 1
+ async: 1
+ poll: 0
+ changed_when: false
+ when: (enabled_i2c|changed) or (set_dtoverlay|changed) or (updated_dtoverlay|changed)
+ register: rebooting
+ become: true
+
+- name: Pause to let the existing control connection expire
+ pause: seconds=30
+ when: not rebooting|skipped
+
+- name: Wait for system to boot up
+ become: false
+ local_action: shell ansible -u {{ ansible_user_id }} -m ping {{ ansible_ssh_host }}
+ register: result
+ until: result.rc == 0
+ retries: 30
+ delay: 10
+ changed_when: false
+ when: not rebooting|skipped
+
+# Check our status
+- name: Check the timedatectl status
+ command: timedatectl status
+ register: time_status
+ changed_when: false
+- debug:
+ msg: "{{ time_status.stdout_lines }}"
+
+- name: Check the temperature
+ command: awk '{print $0/1000 "C (" $0*9/5000+32 "F)"}' /sys/devices/platform/soc/3f804000.i2c/i2c-1/1-0068/hwmon/hwmon0/temp1_input
+ register: temperature
+ changed_when: false
+- debug:
+ msg: "Temperature: {{ temperature.stdout }}"
...
# vi: set ts=2 sts=2 sw=2 et ft=yaml: