131 lines
5.4 KiB
YAML
131 lines
5.4 KiB
YAML
---
|
|
# vim: foldmarker=[[[,]]]:foldmethod=marker
|
|
|
|
# Copyright (C) 2017 Robin Schneider <ypid@riseup.net>
|
|
# Copyright (C) 2017 DebOps <https://debops.org/>
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
- name: Ensure specified packages are in there desired state
|
|
ansible.builtin.package:
|
|
name: '{{ q("flattened", homeassistant__combined_packages) }}'
|
|
when: (homeassistant__deploy_state == "present")
|
|
register: homeassistant__register_packages
|
|
until: homeassistant__register_packages is succeeded
|
|
tags: [ 'role::homeassistant:pkgs' ]
|
|
|
|
# System user and group [[[
|
|
- name: Create Home Assistant system group
|
|
ansible.builtin.group:
|
|
name: '{{ homeassistant__group }}'
|
|
state: '{{ "present" if (homeassistant__deploy_state == "present") else "absent" }}'
|
|
system: True
|
|
|
|
- name: Create Home Assistant system user
|
|
ansible.builtin.user:
|
|
name: '{{ homeassistant__user }}'
|
|
group: '{{ homeassistant__group }}'
|
|
groups: '{{ homeassistant__groups | join(",") | default(omit) }}'
|
|
append: False
|
|
home: '{{ homeassistant__home_path }}'
|
|
comment: '{{ homeassistant__gecos }}'
|
|
shell: '{{ homeassistant__shell }}'
|
|
state: '{{ "present" if (homeassistant__deploy_state == "present") else "absent" }}'
|
|
system: True
|
|
# ]]]
|
|
|
|
- name: Clone Home Assistant git repository
|
|
ansible.builtin.git:
|
|
repo: '{{ homeassistant__git_repo }}'
|
|
dest: '{{ homeassistant__git_dest }}'
|
|
depth: '{{ homeassistant__git_depth }}'
|
|
version: '{{ homeassistant__git_version }}'
|
|
recursive: '{{ homeassistant__git_recursive | bool }}'
|
|
update: '{{ homeassistant__git_update | bool }}'
|
|
become: True
|
|
become_user: '{{ homeassistant__user }}'
|
|
register: homeassistant__register_git
|
|
when: (homeassistant__deploy_state == "present")
|
|
|
|
- name: Install hass without virtualenv
|
|
ansible.builtin.pip: # noqa no-handler
|
|
name: '.'
|
|
chdir: '{{ homeassistant__git_dest }}'
|
|
executable: 'pip3'
|
|
extra_args: '--user --upgrade'
|
|
become: True
|
|
become_user: '{{ homeassistant__user }}'
|
|
when: not homeassistant__virtualenv | bool and homeassistant__register_git is changed
|
|
notify: [ 'Restart Home Assistant' ]
|
|
|
|
- name: Install hass in virtualenv
|
|
ansible.builtin.pip: # noqa no-handler
|
|
name: '.'
|
|
chdir: '{{ homeassistant__git_dest }}'
|
|
extra_args: '--upgrade'
|
|
virtualenv: '{{ homeassistant__virtualenv_path }}'
|
|
virtualenv_python: 'python3'
|
|
become: True
|
|
become_user: '{{ homeassistant__user }}'
|
|
when: homeassistant__virtualenv | bool and homeassistant__register_git is changed
|
|
notify: [ 'Restart Home Assistant' ]
|
|
|
|
# https://community.home-assistant.io/t/wth-why-are-brand-icons-a-cloud-dependency/226359/13
|
|
# Does not work. Home assistant still requests the files from https://brands.home-assistant.io/ …
|
|
# - name: Change hardcoded brands.home-assistant.io domain and point to Nginx
|
|
# ansible.builtin.shell: |
|
|
# set -o pipefail -o errexit;
|
|
# for i in $(find lib/python*/site-packages/hass_frontend/ lib/python*/site-packages/homeassistant/components/ -iname '*.js.gz' -type f); do zcat "$i" | sed --regexp-extended 's#https://brands\.home-assistant\.io/#https://{{ homeassistant__fqdn }}/local_brands/brands/#g;s#brands\.home-assistant\.io#{{ homeassistant__fqdn }}#g;' > "$i.copy"; gzip "$i.copy"; mv "$i.copy.gz" "$i" ; done
|
|
# find lib/python*/site-packages/hass_frontend/ lib/python*/site-packages/homeassistant/components/ -not -iname '*.gz' -type f -print0 | xargs --null sed --in-place --regexp-extended 's#https://brands\.home-assistant\.io/#https://{{ homeassistant__fqdn }}/local_brands/brands/#g;s#brands\.home-assistant\.io#{{ homeassistant__fqdn }}#g;'
|
|
# args:
|
|
# chdir: '{{ homeassistant__virtualenv_path }}'
|
|
# executable: 'bash'
|
|
# become: True
|
|
# become_user: '{{ homeassistant__user }}'
|
|
# when: homeassistant__register_git is changed
|
|
|
|
- name: Ensure Home Assistant config dir exists
|
|
ansible.builtin.file:
|
|
path: '{{ homeassistant__home_path }}/.homeassistant'
|
|
mode: '0750'
|
|
state: 'directory'
|
|
become: True
|
|
become_user: '{{ homeassistant__user }}'
|
|
when: (homeassistant__deploy_state == "present")
|
|
|
|
- name: Ensure Home Assistant www dir exists
|
|
ansible.builtin.file:
|
|
path: '{{ homeassistant__home_path }}/www'
|
|
owner: '{{ homeassistant__user }}'
|
|
group: '{{ homeassistant__webserver_user }}'
|
|
mode: '0750'
|
|
state: 'directory'
|
|
when: (homeassistant__deploy_state == "present")
|
|
|
|
- name: Ensure Home Assistant www in config dir is a symlink
|
|
ansible.builtin.file:
|
|
src: '{{ homeassistant__home_path }}/www'
|
|
dest: '{{ homeassistant__home_path }}/.homeassistant/www'
|
|
state: 'link'
|
|
mode: '0755'
|
|
become: True
|
|
become_user: '{{ homeassistant__user }}'
|
|
when: (homeassistant__deploy_state == "present")
|
|
|
|
- name: Configure systemd unit file
|
|
ansible.builtin.template:
|
|
src: 'etc/systemd/system/home-assistant.service.j2'
|
|
dest: '/etc/systemd/system/home-assistant.service'
|
|
owner: 'root'
|
|
group: 'root'
|
|
mode: '0644'
|
|
register: homeassistant__register_systemd_unit_file
|
|
when: (homeassistant__deploy_state == "present")
|
|
|
|
- name: Set Home Assistant state using systemd
|
|
ansible.builtin.systemd:
|
|
name: 'home-assistant'
|
|
state: '{{ "started" if (homeassistant__deploy_state == "present") else "stopped" }}'
|
|
enabled: True
|
|
masked: False
|
|
daemon_reload: '{{ homeassistant__register_systemd_unit_file is changed }}'
|
|
when: (homeassistant__deploy_state == "present" and ansible_distribution_release not in ["trusty"])
|