--- /dev/null
+- name: Install packages
+ hosts: domoticamachines
+ tasks:
+ - name: create HA user
+ user:
+ name: "domotica"
+ comment: "Home Assistant"
+ system: yes
+ shell: "/sbin/nologin"
+ become: true
+ - name: create HA directory
+ file:
+ path: "/home/domotica/ha/"
+ state: directory
+ mode: 02775
+ owner: "domotica"
+ group: "domotica"
+ become: true
+
+ - name: install required python modules (pre-install)
+ pip:
+ name: "{{ item }}"
+ extra_args: "--upgrade"
+ virtualenv: "/home/domotica/ha/"
+ with_items:
+ - colorlog
+ become: true
+ - name: install defined version of Home Assistant
+ pip:
+ name: homeassistant
+ version: "2024.2.2"
+ virtualenv: "/home/domotica/ha/"
+ when: ha_version is defined
+ become: true
+ - name: install latest version of Home Assistant
+ pip:
+ name: homeassistant
+ extra_args: "--upgrade"
+ virtualenv: "/home/domotica/ha/"
+ when: ha_version is undefined
+ become: true
+ - name: install homeassistant startup script
+ template:
+ src: homeassistant
+ dest: "/usr/local/etc/rc.d/homeassistant"
+ owner: root
+ group: wheel
+ mode: 0755
+ become: true
+ - name: start home assistant
+ community.general.sysrc:
+ name: homeassistant_enable
+ value: "YES"
+ become: true
+ - name: Start homeassistant
+ ansible.builtin.service:
+ name: homeassistant
+ state: started
+ become: true
--- /dev/null
+#!/bin/sh
+#
+
+# PROVIDE: homeassistant
+# REQUIRE: network
+# BEFORE: DAEMON
+
+. /etc/rc.subr
+
+name="homeassistant"
+rcvar=${name}_enable
+pidfile=/var/run/${name}.pid
+procname=/home/domotica/ha/bin/hass
+
+command=/usr/sbin/daemon
+command_args=" -f -S -p ${pidfile} -u domotica ${procname} --ignore-os-check"
+
+load_rc_config $name
+run_rc_command $1