homeassistant: Initial version of role

This commit is contained in:
Timo Makinen 2023-01-29 18:49:38 +00:00
parent f3fc1b3f63
commit 810e64dde7
6 changed files with 108 additions and 0 deletions

View file

@ -0,0 +1,2 @@
---
homeassistant_version: stable

View file

@ -0,0 +1,8 @@
#!/bin/sh
set -eu
curl -sf -X POST -H "Content-Type: application/json" -d @- \
https://id.foo.sh/authcheck <<EOF
{"username": "${username}", "password": "${password}", "group": "foosh"}
EOF

View file

@ -0,0 +1,5 @@
---
- name: Restart homeassistant
ansible.builtin.service:
name: homeassistant-container
state: restarted

View file

@ -0,0 +1,4 @@
---
dependencies:
- {role: nginx}
- {role: podman}

View file

@ -0,0 +1,71 @@
---
- name: Create group
ansible.builtin.group:
name: ha
- name: Create user
ansible.builtin.user:
name: ha
comment: Podman HomeAssistant
group: ha
shell: /sbin/nologin
- name: Fix SELinux contexts from config directory
community.general.sefcontext:
path: /export/homeassistant(/.*)?
setype: container_file_t
when: ansible_selinux_python_present
- name: Create config directory
ansible.builtin.file:
path: /export/homeassistant
state: directory
mode: 0700
owner: ha
group: ha
setype: _default
- name: Link config directory
ansible.builtin.file:
dest: /srv/homeassistant
src: /export/homeassistant
state: link
owner: root
group: "{{ ansible_wheel }}"
follow: false
- name: Copy authentication command
ansible.builtin.copy:
dest: /srv/homeassistant/auth-command.sh
src: auth-command.sh
mode: 0755
owner: root
group: "{{ ansible_wheel }}"
setype: _default
- name: Create service file
ansible.builtin.template:
dest: /etc/systemd/system/homeassistant-container.service
src: homeassistant-container.service.j2
mode: 0644
owner: root
group: "{{ ansible_wheel }}"
notify: Restart homeassistant
- name: Enable service
ansible.builtin.service:
name: homeassistant-container
state: started
enabled: true
- name: Copy nginx config
ansible.builtin.copy:
dest: "/etc/nginx/conf.d/{{ inventory_hostname }}/homeassistant.conf"
content: |
location / {
proxy_pass http://127.0.0.1:8001;
}
mode: 0644
owner: root
group: "{{ ansible_wheel }}"
notify: Restart nginx

View file

@ -0,0 +1,18 @@
[Unit]
Description=HomeAssistant Container
Wants=network-online.target
After=network-online.target
[Service]
User=ha
ExecStart=/usr/bin/podman run \
--rm -p 127.0.0.1:8001:8123 \
--name homeassistant \
--env TZ=Europe/Helsinki \
--volume /srv/homeassistant:/config:rw \
docker.io/homeassistant/home-assistant:{{ homeassistant_version }}
ExecStop=/usr/bin/podman stop --ignore homeassistant
ExecStopPost=/usr/bin/podman rm -f --ignore homeassistant
[Install]
WantedBy=multi-user.target