Created custom automationhat role.
authorLuke Hoersten <luke@hoersten.org>
Tue, 30 Jan 2018 08:41:33 -0600
changeset 9 511e97bd5566
parent 8 e7007d23a144
child 10 38c4094d0d57
Created custom automationhat role.
roles/automationhat/defaults/main.yaml
roles/automationhat/tasks/main.yaml
roles/hap-nodejs/tasks/main.yaml
roles/rpi-base/defaults/main.yaml
roles/rpi-base/tasks/main.yml
rpi-door.yaml
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roles/automationhat/defaults/main.yaml	Tue Jan 30 08:41:33 2018 -0600
@@ -0,0 +1,12 @@
+---
+
+automationhat_apt_packages:
+  - "python3"
+  - "raspi-gpio"
+  - "python3-rpi.gpio"
+  - "python3-smbus"
+  - "python3-sn3218"
+
+automationhat_modules:
+  - "i2c-bcm2708"
+  - "i2c-dev"
--- a/roles/automationhat/tasks/main.yaml	Mon Jan 29 23:19:00 2018 -0600
+++ b/roles/automationhat/tasks/main.yaml	Tue Jan 30 08:41:33 2018 -0600
@@ -1,13 +1,37 @@
 ---
 
-- name: download automationhat install script
-  get_url:
-    url: "https://get.pimoroni.com/automationhat"
-    dest: "/tmp/automationhat.sh"
-    mode: 0750
+# Based on https://get.pimoroni.com/automationhat script
+
+- name: install automationhat apt packages
+  become: yes
+  apt: name="{{item}}"
+  with_items: "{{automationhat_apt_packages}}"
+
+- name: configure i2c boot config
+  become: yes
+  lineinfile:
+    path: "/boot/config.txt"
+    line: "dtparam=i2c_arm=on"
+    insertafter: "^#dtparam=i2c_arm=on"
 
-- name: install automationhat
-  shell: "/tmp/automationhat.sh"
-  args:
-    chdir: "/tmp"
-    executable: "/bin/bash"
+- name: configure i2c kernel modules
+  become: yes
+  lineinfile:
+    path: "/etc/modules"
+    line: "{{item}}"
+  with_items: "{{automationhat_modules}}"
+
+- name: modprobe kernel modules
+  become: yes
+  modprobe: name="{{item}}"
+  with_items: "{{automationhat_modules}}"
+
+- name: dtparam i2c
+  become: yes
+  command: "dtparam i2c_arm=on"
+  changed_when: false
+
+- name: enable i2c with raspi-config
+  become: yes
+  command: "raspi-config nonint do_i2c 0"
+  changed_when: false
--- a/roles/hap-nodejs/tasks/main.yaml	Mon Jan 29 23:19:00 2018 -0600
+++ b/roles/hap-nodejs/tasks/main.yaml	Tue Jan 30 08:41:33 2018 -0600
@@ -36,6 +36,7 @@
 - name: clean up accessory examples
   become: yes
   file: path="{{hap_dest}}/accessories" state="absent"
+  changed_when: false
 
 - name: create accessories dir
   become: yes
@@ -44,6 +45,17 @@
     state: "directory"
     owner: "{{hap_user}}"
     group: "{{hap_user}}"
+  changed_when: false
+
+- name: install door accessory
+  become: yes
+  copy:
+    src: "../../../src/Door_accessory.js"
+    dest: "{{hap_dest}}/accessories/Door_accessory.js"
+    owner: "{{hap_user}}"
+    group: "{{hap_user}}"
+  notify: restart hap-nodejs service
+  changed_when: false
 
 - name: create python dir
   become: yes
@@ -63,15 +75,6 @@
     mode: "0755"
   notify: restart hap-nodejs service
 
-- name: install door accessory
-  become: yes
-  copy:
-    src: "../../../src/Door_accessory.js"
-    dest: "{{hap_dest}}/accessories/Door_accessory.js"
-    owner: "{{hap_user}}"
-    group: "{{hap_user}}"
-  notify: restart hap-nodejs service
-
 - name: build HAP-NodeJS
   become: yes
   become_user: "{{hap_user}}"
--- a/roles/rpi-base/defaults/main.yaml	Mon Jan 29 23:19:00 2018 -0600
+++ b/roles/rpi-base/defaults/main.yaml	Tue Jan 30 08:41:33 2018 -0600
@@ -1,7 +1,7 @@
 ---
 
-ubuntu_base_apt_packages:
-  - emacs-nox
-  - python3
-  - htop
-  - jq
+rpi_base_apt_packages:
+  - "emacs-nox"
+  - "python3"
+  - "htop"
+  - "jq"
--- a/roles/rpi-base/tasks/main.yml	Mon Jan 29 23:19:00 2018 -0600
+++ b/roles/rpi-base/tasks/main.yml	Tue Jan 30 08:41:33 2018 -0600
@@ -23,7 +23,7 @@
 - name: install extra apt packages
   become: yes
   apt: name="{{item}}"
-  with_items: "{{ubuntu_base_apt_packages}}"
+  with_items: "{{rpi_base_apt_packages}}"
 
 - name: authorize admin ssh keys
   become: yes
--- a/rpi-door.yaml	Mon Jan 29 23:19:00 2018 -0600
+++ b/rpi-door.yaml	Tue Jan 30 08:41:33 2018 -0600
@@ -3,5 +3,5 @@
 - hosts: raspberrypi
   roles:
     - rpi-base
-    # - automationhat
+    - automationhat
     - hap-nodejs