modify role hass to work with venv

This commit is contained in:
vincent 2020-03-01 16:18:48 +01:00
parent a330f2cedf
commit 9c0567602d
4 changed files with 67 additions and 10 deletions

View File

@ -1,12 +1,16 @@
--- ---
# defaults file for hass # defaults file for hass
hass_python_package:
- mysqlclient
- homeassistant
hass_conf_folder: /var/lib/hass hass_conf_folder: /var/lib/hass
hass_pacman_name: home-assistant hass_venv_location: /opt/venv/hass
hass_db_name: hass hass_db_name: hass
hass_db_user: hass hass_db_user: hass
hass_SQl_target_file: / hass_SQl_target_file: /
hass_db_password: toto hass_db_password: toto
hass_repo: git hass_repo: git
hass_repo_branch: master hass_repo_branch: master
hass_user: [] hass_username: hass
hass_users: []

View File

@ -7,3 +7,4 @@
state: restarted state: restarted
when: ansible_service_mgr == "systemd" when: ansible_service_mgr == "systemd"
become: yes become: yes

View File

@ -28,19 +28,45 @@
priv: "{{ hass_db_name }}.*:ALL" priv: "{{ hass_db_name }}.*:ALL"
state: present state: present
- name: install HASS - name: create hass user
pacman: become: yes
state: present # not required. choices: absent;latest;present. Desired state of the package. user:
name: "{{hass_pacman_name}}" # not required. Name or list of names of the packages to install, upgrade, or remove. name: "{{hass_username}}" # required. Name of the user to create, remove or modify.
create_home: yes
state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated.
shell: usr/bin/nologin
home: "{{ hass_conf_folder }}"
comment: "Home Assistant daemon user"
- name: ensure venv folder exist
file:
name: "{{hass_venv_location}}"
state: directory
owner: "{{hass_username}}"
group: "{{hass_username}}"
mode: 0777
become: yes become: yes
- name: add {{user.name}} to hass group
- name: create venv
pip:
name: "{{hass_python_package}}"
virtualenv: "{{hass_venv_location}}"
virtualenv_command: /usr/bin/python -m venv
become: true
become_user: "{{hass_username}}"
- name: add user to hass group
become: true become: true
user: user:
name: "{{ item }}" name: "{{ item }}"
groups: hass groups:
- "{{hass_username}}"
append: true append: true
with_items: "{{ hass_user }}" with_items: "{{ hass_users }}"
- name: check repo - name: check repo
become: yes become: yes
@ -99,6 +125,21 @@
name: "auto commit HASS config" # not required. Description of a crontab entry or, if env is set, the name of environment variable. Required if state=absent. Note that if name is not set and state=present, then a new crontab entry will always be created, regardless of existing ones. name: "auto commit HASS config" # not required. Description of a crontab entry or, if env is set, the name of environment variable. Required if state=absent. Note that if name is not set and state=present, then a new crontab entry will always be created, regardless of existing ones.
become: yes become: yes
- name: copy systemd file
template:
src: home-assistant.service.j2
dest: /etc/systemd/system/home-assistant.service
notify:
- restart hass
become: yes
register: hass_service_changed
- name: Reload systemd
systemd:
daemon_reload: yes
become: yes
when: hass_service_changed.changed
- name: enable HASS - name: enable HASS
service: service:
name: home-assistant # required. Name of the service. name: home-assistant # required. Name of the service.

View File

@ -0,0 +1,11 @@
[Unit]
Description=Home Assistant
After=network-online.target
[Service]
Type=simple
User={{hass_username}}
ExecStart={{hass_venv_location}}/bin/hass -c "{{hass_conf_folder}}"
[Install]
WantedBy=multi-user.target