Created hap-nodejs user.
authorLuke Hoersten <luke@hoersten.org>
Mon, 29 Jan 2018 23:19:00 -0600
changeset 8 e7007d23a144
parent 7 55b8db128364
child 9 511e97bd5566
Created hap-nodejs user.
roles/hap-nodejs/defaults/main.yaml
roles/hap-nodejs/tasks/main.yaml
--- a/roles/hap-nodejs/defaults/main.yaml	Mon Jan 29 22:45:54 2018 -0600
+++ b/roles/hap-nodejs/defaults/main.yaml	Mon Jan 29 23:19:00 2018 -0600
@@ -6,8 +6,8 @@
 hap_npm_packages:
   - "python-shell"
 
-hap_user: "pi"
+hap_user: "hap-nodejs"
 hap_restart_sec: 10
+hap_dir: "/home/{{hap_user}}"
 hap_src: "https://github.com/KhaosT/HAP-NodeJS/archive/master.zip"
-hap_home: "/home/{{hap_user}}/"
-hap_dest: "{{hap_home}}/HAP-NodeJS-master"
+hap_dest: "{{hap_dir}}/HAP-NodeJS-master"
--- a/roles/hap-nodejs/tasks/main.yaml	Mon Jan 29 22:45:54 2018 -0600
+++ b/roles/hap-nodejs/tasks/main.yaml	Mon Jan 29 23:19:00 2018 -0600
@@ -1,35 +1,80 @@
 ---
 
+- name: create hap-nodejs user
+  become: yes
+  user:
+    name: "{{hap_user}}"
+    comment: "HAP-NodeJS"
+    groups: "spi,i2c,gpio"
+    shell: "/bin/false"
+    home: "{{hap_dir}}"
+    move_home: yes
+  notify: restart hap-nodejs service
+
 - name: install homekit apt packages
   become: yes
   apt: name="{{item}}"
   with_items: "{{hap_ubuntu_apt_packages}}"
 
 - name: download and unarchive HAP-NodeJS
-  unarchive: src="{{hap_src}}" dest="{{hap_home}}" remote_src="yes" creates="{{hap_dest}}"
+  become: yes
+  become_user: "{{hap_user}}"
+  unarchive:
+    src: "{{hap_src}}"
+    dest: "{{hap_dir}}"
+    remote_src: "yes"
+    creates: "{{hap_dest}}"
+    owner: "{{hap_user}}"
+    group: "{{hap_user}}"
 
 - name: install npm packages
+  become: yes
+  become_user: "{{hap_user}}"
   npm: name="{{item}}" path="{{hap_dest}}"
   with_items: "{{hap_npm_packages}}"
 
 - name: clean up accessory examples
+  become: yes
   file: path="{{hap_dest}}/accessories" state="absent"
 
 - name: create accessories dir
-  file: path="{{hap_dest}}/accessories" state="directory"
+  become: yes
+  file:
+    path: "{{hap_dest}}/accessories"
+    state: "directory"
+    owner: "{{hap_user}}"
+    group: "{{hap_user}}"
 
 - name: create python dir
-  file: path="{{hap_dest}}/python" state="directory"
+  become: yes
+  file:
+    path: "{{hap_dest}}/python"
+    state: "directory"
+    owner: "{{hap_user}}"
+    group: "{{hap_user}}"
 
 - name: install doord.py
-  copy: src="../../../src/doord.py" dest="{{hap_dest}}/python/doord.py"
+  become: yes
+  copy:
+    src: "../../../src/doord.py"
+    dest: "{{hap_dest}}/python/doord.py"
+    owner: "{{hap_user}}"
+    group: "{{hap_user}}"
+    mode: "0755"
   notify: restart hap-nodejs service
 
 - name: install door accessory
-  copy: src="../../../src/Door_accessory.js" dest="{{hap_dest}}/accessories/Door_accessory.js"
+  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}}"
   npm: path="{{hap_dest}}"
 
 - name: configure systemd service