From 863e66577c452073153f4bbe7e510aacf8fec551 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Wed, 18 Mar 2026 23:45:30 +0900 Subject: [PATCH] Added homeassistant to the homelab --- ansible/playbooks/homeassistant.yaml | 6 ++ .../roles/homeassistant/handlers/main.yaml | 4 + ansible/roles/homeassistant/tasks/main.yaml | 88 +++++++++++++++++++ .../templates/configuration.yaml.j2 | 7 ++ .../templates/docker-compose.yaml.j2 | 10 +++ .../templates/homeassistant.service.j2 | 15 ++++ manifests/homeassistant/homeassistant.yaml | 51 +++++++++++ values/pihole.yaml | 3 +- 8 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 ansible/playbooks/homeassistant.yaml create mode 100644 ansible/roles/homeassistant/handlers/main.yaml create mode 100644 ansible/roles/homeassistant/tasks/main.yaml create mode 100644 ansible/roles/homeassistant/templates/configuration.yaml.j2 create mode 100644 ansible/roles/homeassistant/templates/docker-compose.yaml.j2 create mode 100644 ansible/roles/homeassistant/templates/homeassistant.service.j2 create mode 100644 manifests/homeassistant/homeassistant.yaml diff --git a/ansible/playbooks/homeassistant.yaml b/ansible/playbooks/homeassistant.yaml new file mode 100644 index 0000000..ea495f4 --- /dev/null +++ b/ansible/playbooks/homeassistant.yaml @@ -0,0 +1,6 @@ +--- +- name: Deploy Home Assistant on Minisforum + hosts: minisforum + become: yes + roles: + - homeassistant \ No newline at end of file diff --git a/ansible/roles/homeassistant/handlers/main.yaml b/ansible/roles/homeassistant/handlers/main.yaml new file mode 100644 index 0000000..9f4fae0 --- /dev/null +++ b/ansible/roles/homeassistant/handlers/main.yaml @@ -0,0 +1,4 @@ +--- +- name: reload systemd + systemd: + daemon_reload: yes \ No newline at end of file diff --git a/ansible/roles/homeassistant/tasks/main.yaml b/ansible/roles/homeassistant/tasks/main.yaml new file mode 100644 index 0000000..fd5a01f --- /dev/null +++ b/ansible/roles/homeassistant/tasks/main.yaml @@ -0,0 +1,88 @@ +--- +- name: Install Docker prerequisites + apt: + name: + - ca-certificates + - curl + state: present + update_cache: yes + +- name: Create apt keyrings directory + file: + path: /etc/apt/keyrings + state: directory + mode: "0755" + +- name: Download Docker GPG key + get_url: + url: https://download.docker.com/linux/debian/gpg + dest: /etc/apt/keyrings/docker.asc + mode: "0644" + +- name: Add Docker apt repository + apt_repository: + repo: "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian trixie stable" + state: present + filename: docker + +- name: Install Docker CE and Compose plugin + apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: present + update_cache: yes + +- name: Enable and start Docker + systemd: + name: docker + enabled: yes + state: started + +- name: Add nik to docker group + user: + name: nik + groups: docker + append: yes + +- name: Create HA config directory + file: + path: /home/nik/homeassistant/config + state: directory + owner: nik + group: nik + mode: "0755" + +- name: Deploy docker-compose.yaml + template: + src: docker-compose.yaml.j2 + dest: /home/nik/homeassistant/docker-compose.yaml + owner: nik + group: nik + mode: "0644" + +- name: Deploy systemd unit + template: + src: homeassistant.service.j2 + dest: /etc/systemd/system/homeassistant.service + mode: "0644" + notify: reload systemd + +- name: Deploy base configuration.yaml + template: + src: configuration.yaml.j2 + dest: /home/nik/homeassistant/config/configuration.yaml + owner: nik + group: nik + mode: "0644" + force: no + +- name: Enable and start homeassistant + systemd: + name: homeassistant + enabled: yes + state: started + daemon_reload: yes \ No newline at end of file diff --git a/ansible/roles/homeassistant/templates/configuration.yaml.j2 b/ansible/roles/homeassistant/templates/configuration.yaml.j2 new file mode 100644 index 0000000..faaebbe --- /dev/null +++ b/ansible/roles/homeassistant/templates/configuration.yaml.j2 @@ -0,0 +1,7 @@ +# Home Assistant configuration +http: + use_x_forwarded_for: true + trusted_proxies: + - 127.0.0.1 + - 192.168.7.0/24 + - 10.42.0.0/16 \ No newline at end of file diff --git a/ansible/roles/homeassistant/templates/docker-compose.yaml.j2 b/ansible/roles/homeassistant/templates/docker-compose.yaml.j2 new file mode 100644 index 0000000..3fa9cd7 --- /dev/null +++ b/ansible/roles/homeassistant/templates/docker-compose.yaml.j2 @@ -0,0 +1,10 @@ +services: + homeassistant: + container_name: homeassistant + image: ghcr.io/home-assistant/home-assistant:stable + network_mode: host + volumes: + - /home/nik/homeassistant/config:/config + - /etc/localtime:/etc/localtime:ro + restart: unless-stopped + privileged: true \ No newline at end of file diff --git a/ansible/roles/homeassistant/templates/homeassistant.service.j2 b/ansible/roles/homeassistant/templates/homeassistant.service.j2 new file mode 100644 index 0000000..f19a634 --- /dev/null +++ b/ansible/roles/homeassistant/templates/homeassistant.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=Home Assistant (Docker Compose) +Requires=docker.service +After=docker.service network-online.target + +[Service] +Type=oneshot +RemainAfterExit=yes +WorkingDirectory=/home/nik/homeassistant +ExecStart=/usr/bin/docker compose up -d +ExecStop=/usr/bin/docker compose down +User=nik + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/manifests/homeassistant/homeassistant.yaml b/manifests/homeassistant/homeassistant.yaml new file mode 100644 index 0000000..ed893f2 --- /dev/null +++ b/manifests/homeassistant/homeassistant.yaml @@ -0,0 +1,51 @@ +--- +apiVersion: v1 +kind: Endpoints +metadata: + name: homeassistant + namespace: default +subsets: + - addresses: + - ip: 192.168.7.77 + ports: + - port: 8123 +--- +apiVersion: v1 +kind: Service +metadata: + name: homeassistant + namespace: default +spec: + ports: + - port: 8123 + targetPort: 8123 +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: homeassistant-cert + namespace: default +spec: + secretName: homeassistant-tls + issuerRef: + name: internal-ca-issuer + kind: ClusterIssuer + dnsNames: + - ha.home.arpa +--- +apiVersion: traefik.io/v1alpha1 +kind: IngressRoute +metadata: + name: homeassistant + namespace: default +spec: + entryPoints: + - websecure + routes: + - match: Host(`ha.home.arpa`) + kind: Rule + services: + - name: homeassistant + port: 8123 + tls: + secretName: homeassistant-tls \ No newline at end of file diff --git a/values/pihole.yaml b/values/pihole.yaml index 6f2c2f8..e59ea8f 100644 --- a/values/pihole.yaml +++ b/values/pihole.yaml @@ -77,4 +77,5 @@ dnsmasq: - address=/auth.home.arpa/192.168.7.77 - address=/traefik.home.arpa/192.168.7.77 - address=/photoview.home.arpa/192.168.7.77 - - address=/gitea.nik4nao.com/192.168.7.77 \ No newline at end of file + - address=/gitea.nik4nao.com/192.168.7.77 + - address=/ha.home.arpa/192.168.7.77 \ No newline at end of file