roles/hap-nodejs/tasks/main.yaml
author Luke Hoersten <luke@hoersten.org>
Tue, 30 Jan 2018 08:41:33 -0600
changeset 9 511e97bd5566
parent 8 e7007d23a144
child 15 6913019b9492
permissions -rw-r--r--
Created custom automationhat role.

---

- 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
  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"
  changed_when: false

- name: create accessories dir
  become: yes
  file:
    path: "{{hap_dest}}/accessories"
    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
  file:
    path: "{{hap_dest}}/python"
    state: "directory"
    owner: "{{hap_user}}"
    group: "{{hap_user}}"

- name: install 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: build HAP-NodeJS
  become: yes
  become_user: "{{hap_user}}"
  npm: path="{{hap_dest}}"

- name: configure systemd service
  become: yes
  template: src="hap-nodejs.service.j2" dest="/lib/systemd/system/hap-nodejs.service"
  notify: restart hap-nodejs service

- name: ensure hap-nodejs is started
  become: yes
  systemd: name="hap-nodejs.service" enabled="yes" state="started"