From e392e201f422b28a8d5a6c96227441f0fbb82fb8 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Sun, 4 Jun 2023 16:59:59 -0400 Subject: [PATCH] add homeassistant role --- hosts | 5 +++ playbook.yml | 4 ++ roles/homeassistant/defaults/main.yml | 0 roles/homeassistant/files/hass.service | 13 ++++++ roles/homeassistant/tasks/main.yml | 61 ++++++++++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 roles/homeassistant/defaults/main.yml create mode 100644 roles/homeassistant/files/hass.service create mode 100644 roles/homeassistant/tasks/main.yml diff --git a/hosts b/hosts index 2bb804b..aed7d75 100644 --- a/hosts +++ b/hosts @@ -30,6 +30,10 @@ all: nfs_libraries: - 192.168.20.30:/mnt/pool0/media/Movies - 192.168.20.30:/mnt/pool0/media/Series + homeassistant: + hosts: + homeassistant: + ansible_host: 192.168.20.32 k3s: children: k3s-server: @@ -63,6 +67,7 @@ all: bastions: k3s: plex: + homeassistant: vars: ansible_user: ansible ansible_password: !vault | diff --git a/playbook.yml b/playbook.yml index 7d52841..8a13088 100644 --- a/playbook.yml +++ b/playbook.yml @@ -21,3 +21,7 @@ - hosts: plex roles: - plex + +- hosts: homeassistant + roles: + - homeassistant \ No newline at end of file diff --git a/roles/homeassistant/defaults/main.yml b/roles/homeassistant/defaults/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/homeassistant/files/hass.service b/roles/homeassistant/files/hass.service new file mode 100644 index 0000000..c58ac46 --- /dev/null +++ b/roles/homeassistant/files/hass.service @@ -0,0 +1,13 @@ +[Unit] +Description=Home Assistant +Documentation=https://www.home-assistant.io +After=network-online.target + +[Service] +Type=simple +User=homeassistant +Group=homeassistant +ExecStart=/srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/roles/homeassistant/tasks/main.yml b/roles/homeassistant/tasks/main.yml new file mode 100644 index 0000000..38799ed --- /dev/null +++ b/roles/homeassistant/tasks/main.yml @@ -0,0 +1,61 @@ +- name: Install packages + apt: + update_cache: yes + name: + - acl # for become unprivileged user + - python3 + - python3-dev + - python3-venv + - python3-pip + - bluez + - libffi-dev + - libssl-dev + - libjpeg-dev + - zlib1g-dev + - autoconf + - build-essential + - libopenjp2-7 + - libtiff5 + - libturbojpeg0-dev + - tzdata + - ffmpeg + - liblapack3 + - liblapack-dev + - libatlas-base-dev + +- name: Add user "homeassistant" + user: + name: homeassistant + create_home: true + system: true + +- name: Create homeassistant install directory + file: + path: /srv/homeassistant + owner: homeassistant + group: homeassistant + state: directory + +- name: Install homeassistant + become_user: homeassistant + pip: + virtualenv: /srv/homeassistant/ + virtualenv_command: /usr/bin/python3 -m venv + name: + - wheel + - homeassistant==2023.5.4 + +- name: Copy hass service file + copy: + src: hass.service + dest: /etc/systemd/system/hass.service + owner: root + group: root + mode: 0644 + +- name: Enable hass service + systemd: + name: hass + daemon_reload: yes + state: started + enabled: yes \ No newline at end of file