diff --git a/meta/main.yml b/meta/main.yml index e95de76..5636280 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -20,6 +20,7 @@ galaxy_info: - name: Debian versions: - jessie + - bookworm categories: - system - home-automation diff --git a/tasks/installation.yml b/tasks/installation.yml index 6026400..f334649 100644 --- a/tasks/installation.yml +++ b/tasks/installation.yml @@ -5,24 +5,23 @@ # Licensed under Apache 2.0. All rights reserved. # --- -- name: install required python modules (pre-install) - pip: - name: "{{ item }}" - extra_args: "--upgrade" - executable: pip3 - with_items: - - colorlog - name: install defined version of Home Assistant + become: true + become_user: "{{ ha_user }}" pip: name: homeassistant version: "{{ ha_version }}" - executable: pip3 + virtualenv: "{{ ha_conf_dir }}/{{ ha_venv }}" + virtualenv_command: python3 -m venv when: ha_version is defined - name: install latest version of Home Assistant + become: true + become_user: "{{ ha_user }}" pip: name: homeassistant extra_args: "--upgrade" - executable: pip3 + virtualenv: "{{ ha_conf_dir }}/{{ ha_venv }}" + virtualenv_command: python3 -m venv when: ha_version is undefined diff --git a/tasks/motd.yml b/tasks/motd.yml index ca29117..2ff7251 100644 --- a/tasks/motd.yml +++ b/tasks/motd.yml @@ -6,6 +6,7 @@ # --- - name: distribute the /etc/motd file + become: true template: src: motd.j2 dest: /etc/motd diff --git a/tasks/preparation.yml b/tasks/preparation.yml index c74c062..260ac9b 100644 --- a/tasks/preparation.yml +++ b/tasks/preparation.yml @@ -6,6 +6,7 @@ # --- - name: install commonly-named packages + become: true package: name: "{{ item }}" state: present @@ -30,34 +31,47 @@ when: ansible_distribution == "Fedora" - name: install debian-specific packages + become: true package: name: "{{ item }}" state: present with_items: - python3-dev - when: ansible_distribution == "Debian" - -- name: install debian-required pip packages - pip: - name: "{{ item }}" - state: present - executable: pip3 - with_items: - - appdirs - - packaging + - python3-venv + - acl + - ffmpeg when: ansible_distribution == "Debian" - name: create user + become: true user: name: "{{ ha_user }}" comment: "Home Assistant" system: yes - shell: "/sbin/nologin" + shell: "/bin/bash" - name: create directory + become: true file: - path: "{{ ha_conf_dir }}" + path: "{{ ha_conf_dir }}/.homeassistant" state: directory + recurse: yes mode: 02775 owner: "{{ ha_user }}" group: "{{ ha_user }}" + +- name: install debian-required pip packages + become: true + become_user: "{{ ha_user }}" + become_method: sudo + pip: + name: + - appdirs + - packaging + - colorlog + - wheel + state: present + virtualenv: "{{ ha_conf_dir }}/{{ ha_venv }}" + virtualenv_command: python3 -m venv + extra_args: "--upgrade" + when: ansible_distribution == "Debian" diff --git a/tasks/systemd.yml b/tasks/systemd.yml index 20d9f1b..532d4e7 100644 --- a/tasks/systemd.yml +++ b/tasks/systemd.yml @@ -5,10 +5,11 @@ # Licensed under Apache 2.0. All rights reserved. # --- -- shell: which hass - register: hass_command +#- shell: which hass +# register: hass_command - name: install fedora systemd unit file + become: true template: src: home-assistant.service.j2 dest: "/etc/systemd/system/home-assistant.service" @@ -17,6 +18,7 @@ mode: 0644 - name: start home assistant + become: true systemd: name: home-assistant daemon_reload: yes diff --git a/templates/home-assistant.service.j2 b/templates/home-assistant.service.j2 index 0853825..2074915 100644 --- a/templates/home-assistant.service.j2 +++ b/templates/home-assistant.service.j2 @@ -5,7 +5,8 @@ After=network.target [Service] Type=simple User={{ ha_user }} -ExecStart={{ hass_command.stdout }} --config {{ ha_conf_dir }} +Restart=on-failure +ExecStart={{ ha_conf_dir }}/{{ ha_venv }}/bin/hass --config "{{ ha_conf_dir }}/.homeassistant" [Install] WantedBy=multi-user.target