Skip to content

Commit

Permalink
feat(supervised_install): Switch to deb installer (#29)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The Home Assistant Supervised install.sh convenience script is deprecated.
As a replacement, the install is now performed by installing the homeassistant-supervised.deb package.
Overriding the default values for many of the configurations is not currently possible with the .deb package install, so the role variables related to these configurations have been removed. Any non-default values provided to this role specified in playbooks or inventory will not be used since these variables have been removed from the role.

Fixes #27
  • Loading branch information
jhampson-dbre authored Feb 1, 2022
1 parent 3b75a37 commit 70526ef
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 259 deletions.
39 changes: 20 additions & 19 deletions roles/supervised_install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ Install Home Assistant Supervised on Raspberry Pi 4 running Debian 10 (buster).
Requirements
------------

python3-apt
Python Packages:

- docker

OS Packages:

- python3-apt
- debconf
- debconf-utils

Role Variables
--------------
Expand All @@ -27,25 +35,18 @@ The variables below are specify to the supervised_install role
# Home Assistant. To maintain "full support", these requirements
# can be manually uninstalled if you are done using this role
supervised_install_ansible_requirements: true
```
The variables below correspond to the variables from install.sh with the same values

```yaml
prefix: /usr
sysconfdir: /etc
data_share: "{{ prefix }}/share/hassio"
config: "{{ sysconfdir }}/hassio.json"
docker_repo: homeassistant
binary_docker: /usr/bin/docker
service_docker: "docker.service"
```
The variables below can be provided by the user in install.sh
```yaml
# Allowed values in install.sh are
# intel-nuc|odroid-c2|odroid-n2|odroid-xu|qemuarm|qemuarm-64|qemux86|qemux86-64|raspberrypi|raspberrypi2|raspberrypi3|raspberrypi4|raspberrypi3-64|raspberrypi4-64|tinker
# Number of seconds the homeassistant-supervised deb package installation
# can run before considered to be failed due to timeout
supervised_install_deb_timeout: 600

# The homeassistant-supervised installer may prompt for the machine type.
# The default response for silent install can be configured.
#
# Allowed values in homeassistant-supervised.deb are:
# generic-x86-64, odroid-c2, odroid-n2, odroid-xu, qemuarm, qemuarm-64,
# qemux86, qemux86-64, raspberrypi, raspberrypi2, raspberrypi3, raspberrypi4,
# raspberrypi3-64, raspberrypi4-64, tinker, khadas-vim3r
machine: raspberrypi4-64
```
Expand Down
13 changes: 1 addition & 12 deletions roles/supervised_install/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
---
supervised_install_ansible_requirements: true
prefix: /usr
sysconfdir: /etc
data_share: "{{ prefix }}/share/hassio"
config: "{{ sysconfdir }}/hassio.json"
HASSIO_CONFIG: "/etc/hassio.json" # noqa var-naming
supervised_install_deb_timeout: 600
machine: raspberrypi4-64
docker_repo: homeassistant
binary_docker: /usr/bin/docker
BINARY_DOCKER: "/usr/bin/docker" # noqa var-naming
service_docker: "docker.service"
SERVICE_DOCKER: "docker.service" # noqa var-naming
HASSIO_APPARMOR_BINARY: "/usr/sbin/hassio-apparmor" # noqa var-naming
BINARY_HASSIO: "/usr/sbin/hassio-supervisor" # noqa var-naming
18 changes: 0 additions & 18 deletions roles/supervised_install/handlers/main.yml

This file was deleted.

210 changes: 13 additions & 197 deletions roles/supervised_install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,6 @@
enabled: no
state: stopped

- name: Make temp directory for downloading Network Manager and Docker config files
tempfile:
state: directory
suffix: supervised_config
run_once: true
delegate_to: localhost
register: temp_config_dir
become: no
notify:
- cleanup temp dir

- name: Download NetworkManager and Docker config files
get_url:
url: https://raw.githubusercontent.com/home-assistant/supervised-installer/master/files/{{ config_file_name }}
dest: "{{ temp_config_dir.path }}/{{ config_file_name }}"
mode: "0440"
loop:
- NetworkManager.conf
- docker_daemon.json
- interfaces
- system-connection-default
loop_control:
loop_var: config_file_name
run_once: true
delegate_to: localhost
become: no

- name: Create Docker config directory
file:
path: /etc/docker
state: directory
mode: "0755"

- name: Set up docker config file
copy:
src: "{{ temp_config_dir.path }}/docker_daemon.json"
dest: /etc/docker/daemon.json
mode: "0644"
notify:
- restart docker

- name: Fix kernel dmesg restriction
sysctl:
name: kernel.dmesg_restrict
Expand All @@ -76,33 +35,6 @@
state: present
reload: yes

- name: Create config for NetworkManager
copy:
src: "{{ networkmanager_file['source'] }}"
dest: "{{ networkmanager_file['target'] }}"
mode: "0644"
loop:
- source: "{{ temp_config_dir.path }}/NetworkManager.conf"
target: /etc/NetworkManager/NetworkManager.conf
- source: "{{ temp_config_dir.path }}/system-connection-default"
target: /etc/NetworkManager/system-connections/default
loop_control:
loop_var: networkmanager_file
label: "{{ networkmanager_file['source'] }}"
notify:
- restart networkmanager

- name: Overwrite network interfaces file
copy:
src: "{{ temp_config_dir.path }}/interfaces"
dest: /etc/network/interfaces
mode: "0644"
notify:
- restart networkmanager

- name: Ensure all changed service are restarted
meta: flush_handlers

- name: Get download url for latest os-agent .deb release
shell: |
curl -s https://api.github.com/repos/home-assistant/os-agent/releases/latest \
Expand All @@ -120,136 +52,20 @@
apt:
deb: "{{ os_agent_latest_url.stdout|trim }}"

- name: Init folders
file:
path: "{{ data_share }}"
state: directory
mode: "0755"

- name: Write config
template:
src: hassio.j2
dest: "{{ config }}"
mode: "0644"

- name: Read version infos from web
uri:
body_format: json
url: https://version.home-assistant.io/stable.json
register: hassio_stable_out

- name: Set hassio_version fact
set_fact:
hassio_version: "{{ hassio_stable_out['json']['supervisor'] }}"

- name: Install supervisor Docker container
docker_image:
name: "{{ arch[ansible_architecture]['hassio_docker'] }}:{{ hassio_version }}"
source: pull
state: present

- name: Add tag latest to supervisor image
docker_image:
name: "{{ arch[ansible_architecture]['hassio_docker'] }}:{{ hassio_version }}"
repository: "{{ arch[ansible_architecture]['hassio_docker'] }}:latest"
# As 'latest' usually already is present, we need to enable overwriting of existing tags
force_tag: yes
source: local

- name: Make temp directory for downloading Home Assistant config files
tempfile:
state: directory
suffix: supervised_config
run_once: true
delegate_to: localhost
register: temp_config_dir
become: no
notify:
- cleanup temp dir
- name: Set machine type for homeassistant-supervised install
debconf:
name: homeassistant-supervised
question: ha/machine-type
value: "{{ machine }}"
vtype: select

- name: Download Home Assistant config files
get_url:
url: https://raw.githubusercontent.com/home-assistant/supervised-installer/master/files/{{ config_file_name }}
dest: "{{ temp_config_dir.path }}/{{ config_file_name }}"
mode: "0440"
become: no
loop:
- ha
- hassio-apparmor
- hassio-apparmor.service
- hassio-supervisor
- hassio-supervisor.service
loop_control:
loop_var: config_file_name
run_once: true
delegate_to: localhost

- name: Install supervisor startup script
template:
src: "{{ temp_config_dir.path }}/hassio-supervisor"
dest: "{{ prefix }}/sbin/hassio-supervisor"
mode: a+x
variable_start_string: "%%"
variable_end_string: "%%"

- name: Install supervisor service file
template:
src: "{{ temp_config_dir.path }}/hassio-supervisor.service"
dest: "{{ sysconfdir }}/systemd/system/hassio-supervisor.service"
mode: "0644"
variable_start_string: "%%"
variable_end_string: "%%"

- name: Enable supervisor service
service:
name: hassio-supervisor
enabled: yes

- name: Create AppArmor directory
file:
path: "{{ data_share }}/apparmor"
state: directory
mode: "0755"

- name: Install AppArmor startup script
template:
src: "{{ temp_config_dir.path }}/hassio-apparmor"
dest: "{{ prefix }}/sbin/hassio-apparmor"
mode: a+x
variable_start_string: "%%"
variable_end_string: "%%"

- name: Install AppArmor service file
template:
src: "{{ temp_config_dir.path }}/hassio-apparmor.service"
dest: "{{ sysconfdir }}/systemd/system/hassio-apparmor.service"
mode: "0644"
variable_start_string: "%%"
variable_end_string: "%%"

- name: Download AppArmor profile
get_url:
url: https://version.home-assistant.io/apparmor.txt
dest: "{{ data_share }}/apparmor/hassio-supervisor"
mode: "0644"

- name: Enable and start AppArmor service
service:
name: hassio-apparmor
enabled: yes
state: started

# AppArmor service must be started before Home Assistant service
- name: Start Home Assistant Supervised
service:
name: hassio-supervisor
state: started

- name: Install the 'ha' cli
copy:
src: "{{ temp_config_dir.path }}/ha"
dest: "{{ prefix }}/bin/ha"
mode: a+x
# Run async to prevent disconnect when networking is restarted
# by homeasistant-supervised package installer
- name: Install homeassistant-supervised
apt:
deb: https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb
async: "{{ supervised_install_deb_timeout }}"
poll: 10

- name: Home Assistant supervised is now installed
debug:
Expand Down
11 changes: 10 additions & 1 deletion roles/supervised_install/tasks/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
name:
- docker
executable: pip3
extra_args: --user
extra_args: --user

- name: Install OS package requirements for supervised_install # noqa 403
apt:
name:
- debconf
- debconf-utils
state: latest
update_cache: yes
become: true
5 changes: 0 additions & 5 deletions roles/supervised_install/templates/hassio.j2

This file was deleted.

7 changes: 0 additions & 7 deletions roles/supervised_install/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
---
arch:
"i386":
hassio_docker: "{{ docker_repo }}/i386-hassio-supervisor"
os_agent: "i386"
"i686":
hassio_docker: "{{ docker_repo }}/i386-hassio-supervisor"
os_agent: "none"
"x86_64":
hassio_docker: "{{ docker_repo }}/amd64-hassio-supervisor"
os_agent: "x86_64"
"arm":
hassio_docker: "{{ docker_repo }}/armhf-hassio-supervisor"
os_agent: "armv5"
"armv6l":
hassio_docker: "{{ docker_repo }}/armhf-hassio-supervisor"
os_agent: "none"
"armv7l":
hassio_docker: "{{ docker_repo }}/armv7-hassio-supervisor"
os_agent: "armv7"
"aarch64":
hassio_docker: "{{ docker_repo }}/aarch64-hassio-supervisor"
os_agent: "aarch64"

# for geerlingguy.docker
Expand Down

0 comments on commit 70526ef

Please sign in to comment.