Last active
January 22, 2021 22:53
-
-
Save don-rumata/5f9853aaa1ab4e21ddb6fb9065aa8814 to your computer and use it in GitHub Desktop.
Ansible playbook for install Home Assistant in Ubuntu 20.04 over python virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# WORK | |
# https://marvins.ru/avtomatizaciya/ubuntu-ustanovka-home-assistant.html | |
# https://github.com/home-assistant-ecosystem/home-assistant-ansible | |
- name: Install Home Assistant | |
hosts: all | |
strategy: free | |
serial: | |
- "100%" | |
vars: | |
homeassistant_user: homeassistant | |
homeassistant_group: homeassistant | |
homeassistant_home_directory: /opt/homeassistant | |
homeassistant_config_directory: /etc/homeassistant | |
homeassistant_log_directory: /var/log/homeassistant | |
homeassistant_path_to_log: '{{ homeassistant_log_directory }}/homeassistant.log' | |
homeassistant_service_name: home-assistant | |
homeassistant_tcp_port: 8123 | |
# https://github.com/danielperna84/hass-configurator/blob/master/hass-configurator.supervisor | |
# Я, если честно не до конца понимаю как именно эта папка взаимодействует с остальными папками и файлами hass, поэтому сделал максимально близко к оф. версии. | |
homeassistant_configurator_config_directory: '{{ homeassistant_config_directory }}/.homeassistant' | |
# homeassistant_configurator_config_directory: '{{ homeassistant_config_directory }}' | |
homeassistant_configurator_path_to_settings_conf: '{{ homeassistant_configurator_config_directory }}/settings.conf' | |
homeassistant_configurator_service_name: home-assistant-configurator | |
homeassistant_configurator_tcp_port: 3218 | |
# Согласно скрипту установки (https://hacs.xyz/install) - помимо массива - там ещё и поиск файла "configuration.yaml" идёт. Так что в нашем случае - это {{ homeassistant_config_directory }}. | |
homeassistant_custom_components_directory: '{{ homeassistant_config_directory }}/custom_components' | |
homeassistant_community_store_directory: '{{ homeassistant_custom_components_directory }}/hacs' | |
homeassistant_community_store_hacs_archive_name: hacs.zip | |
homeassistant_community_store_hacs_archive_url: https://github.com/hacs/integration/releases/latest/download/{{ homeassistant_community_store_hacs_archive_name }} | |
tasks: | |
# Тестилось только на 20.04, но из-за характера установки - должно работать даже на тостерах. Тем не менее - пока "лучше не надо". | |
- name: Install dependencies 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
package: | |
name: | |
- python3-dev | |
- python3-pip | |
- python3-venv | |
- libffi-dev | |
- libssl-dev | |
- python-idna | |
state: present | |
install_recommends: yes | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- package | |
- name: Create service user and group 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
block: | |
- group: | |
name: "{{ homeassistant_group }}" | |
system: yes | |
state: present | |
- user: | |
name: "{{ homeassistant_user }}" | |
group: "{{ homeassistant_group }}" | |
create_home: yes | |
shell: /bin/bash | |
system: yes | |
groups: | |
- "{{ homeassistant_group }}" | |
- dialout | |
home: "{{ homeassistant_home_directory }}" | |
comment: Service user for Home Assistant | |
state: present | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- user | |
- group | |
- name: Create directory structure 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
file: | |
path: "{{ item }}" | |
owner: "{{ homeassistant_user }}" | |
group: "{{ homeassistant_group }}" | |
state: directory | |
with_items: | |
- "{{ homeassistant_config_directory }}" | |
- "{{ homeassistant_log_directory }}" | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- directory | |
- name: Install Home Assistant 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
become_user: "{{ homeassistant_user }}" | |
# https://stackoverflow.com/a/43108253 | |
block: | |
- pip: | |
name: wheel | |
virtualenv: "{{ homeassistant_home_directory }}" | |
virtualenv_command: python3 -m venv | |
- pip: | |
name: homeassistant | |
virtualenv: "{{ homeassistant_home_directory }}" | |
virtualenv_command: python3 -m venv | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- name: Config service execute 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
block: | |
- copy: | |
content: | | |
[Unit] | |
Description=Home Assistant | |
Documentation=https://www.home-assistant.io/docs | |
After=network.target | |
[Service] | |
Type=simple | |
User={{ homeassistant_user }} | |
Group={{ homeassistant_group }} | |
ExecStart={{ homeassistant_home_directory }}/bin/hass --config {{ homeassistant_config_directory }} --log-file {{ homeassistant_path_to_log }} | |
[Install] | |
WantedBy=multi-user.target | |
dest: /etc/systemd/system/{{ homeassistant_service_name }}.service | |
owner: root | |
group: root | |
mode: 0644 | |
- systemd: | |
name: "{{ homeassistant_service_name }}" | |
daemon_reload: yes | |
enabled: yes | |
state: started | |
- wait_for: | |
port: "{{ homeassistant_tcp_port }}" | |
host: "{{ inventory_hostname }}" | |
state: started | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- service | |
- systemd | |
################################################################################## | |
# https://github.com/danielperna84/hass-configurator | |
- name: Create directory structure 4 Configurator 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
file: | |
path: "{{ item }}" | |
owner: "{{ homeassistant_user }}" | |
group: "{{ homeassistant_group }}" | |
state: directory | |
with_items: | |
- "{{ homeassistant_configurator_config_directory }}" | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- directory | |
- configurator | |
- name: Install Home Assistant Configurator 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
become_user: "{{ homeassistant_user }}" | |
# https://stackoverflow.com/a/43108253 | |
block: | |
- pip: | |
name: hass-configurator | |
virtualenv: "{{ homeassistant_home_directory }}" | |
virtualenv_command: python3 -m venv | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- configurator | |
- name: Config service execute 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
block: | |
- copy: | |
content: | | |
[Unit] | |
Description=Home Assistant Configurator | |
Documentation=https://zen.yandex.ru/media/id/5debe57e86c4a900b03d2e5c/pervonachalnaia-nastroika-homeassistant-5ea408e067003504eddc9c91, https://github.com/danielperna84/hass-configurator/wiki/Installation | |
After=network.target | |
[Service] | |
Type=simple | |
User={{ homeassistant_user }} | |
Group={{ homeassistant_group }} | |
ExecStart={{ homeassistant_home_directory }}/bin/hass-configurator --port {{ homeassistant_configurator_tcp_port }} {{ homeassistant_configurator_path_to_settings_conf }} | |
Restart=always | |
# https://github.com/danielperna84/hass-configurator/blob/master/hass-configurator.systemd#L27 | |
WorkingDirectory={{ homeassistant_config_directory }} | |
[Install] | |
WantedBy=multi-user.target | |
dest: /etc/systemd/system/{{ homeassistant_configurator_service_name }}.service | |
owner: root | |
group: root | |
mode: 0644 | |
- systemd: | |
name: "{{ homeassistant_configurator_service_name }}" | |
daemon_reload: yes | |
enabled: yes | |
state: started | |
- wait_for: | |
port: "{{ homeassistant_configurator_tcp_port }}" | |
host: "{{ inventory_hostname }}" | |
state: started | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- service | |
- systemd | |
- configurator | |
############################################################################### | |
# https://hacs.xyz/docs/installation/installation | |
# curl -sfSL https://hacs.xyz/install | bash - | |
# https://kvshome.ru/?p=1841 | |
- name: Install Home Assistant Community Store 4 {{ ansible_distribution }} | |
when: | |
- ansible_distribution == 'Ubuntu' | |
- ansible_distribution_version == '20.04' | |
become: yes | |
become_user: "{{ homeassistant_user }}" | |
# https://stackoverflow.com/a/43108253 | |
block: | |
- file: | |
path: "{{ item }}" | |
owner: "{{ homeassistant_user }}" | |
group: "{{ homeassistant_group }}" | |
state: directory | |
with_items: | |
- "{{ homeassistant_custom_components_directory }}" | |
- "{{ homeassistant_community_store_directory }}" | |
- get_url: | |
url: '{{ homeassistant_community_store_hacs_archive_url }}' | |
dest: '{{ homeassistant_custom_components_directory }}/{{ homeassistant_community_store_hacs_archive_name }}' | |
- unarchive: | |
src: '{{ homeassistant_custom_components_directory }}/{{ homeassistant_community_store_hacs_archive_name }}' | |
dest: '{{ homeassistant_community_store_directory }}' | |
remote_src: yes | |
tags: | |
- linux | |
- ubuntu | |
- install | |
- homeassistant | |
- iot | |
- community | |
- store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment