Skip to content

Commit

Permalink
feat(install_hacs): Add new role to install Home Assistant Community …
Browse files Browse the repository at this point in the history
…Store
  • Loading branch information
jhampson-dbre authored and Jared Hampson committed Jan 22, 2021
1 parent d584dfe commit 010877f
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A collection of roles for installing and configuring Home Assistant Supervised on Debian 10

**WARNING:** The roles in this collection can make changes to Home Assisant's configuration.yaml and restart Home Assistant. As recommended before making any changes to Home Assisant, ensure you have a good snapshot of your current configuration.

## Roles

### Minimal installation
Expand All @@ -16,4 +18,5 @@ While every effort has been made to ensure these roles complies with ADR-0014, n
These roles provide additional functionality to secure and enhance the minimal install of Home Assistant Supervised. These are roles I use myself and do not comply with ADR-0014.

1. [harden_os](https://github.com/jhampson-dbre/home_assistant/blob/main/roles/harden_os/README.md) - Enable automated Debian security updates and restrict SSH access
1. [fail2ban](https://github.com/jhampson-dbre/home_assistant/blob/main/roles/fail2ban/README.md) - Install fail2ban, configure it to blacklist IPs with excessive failed login attempts to Home Assistant, and add the fail2ban integration to Home Assistant
1. [fail2ban](https://github.com/jhampson-dbre/home_assistant/blob/main/roles/fail2ban/README.md) - Install fail2ban, configure it to blacklist IPs with excessive failed login attempts to Home Assistant, and add the fail2ban integration to Home Assistant
1. [install_hacs](https://github.com/jhampson-dbre/home_assistant/blob/main/roles/install_hacs/README.md) - Install the [Home Assistant Comunity Store](https://hacs.xyz/), a marketplace of community-contributed custom components for Home Assistant
1 change: 1 addition & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tags:
- pi
- home
- assistant
- hacs

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
Expand Down
47 changes: 47 additions & 0 deletions roles/install_hacs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
install_hacs
=========

Install the [Home Assistant Community Store](https://hacs.xyz/) in Home Assistant Supervised. Use this role as an alternative to the HACS [install shell script](https://github.com/hacs/install/blob/main/install).

Requirements
------------

- unzip is required on the target host
- The role must be ran as root or as an alternate user with `become: true`

Role Variables
--------------

The following varaibles are defined in `defaults/main.yml`

```yaml
# The path of the home assistant config directory. You should not need to change this for Supervised installation.
ha_path: /usr/share/hassio/homeassistant

# Automatically install software packages listed under requirements
install_hacs_requirements: true
```
Dependencies
------------
none
Example Playbook
----------------
```yaml
- hosts: pi
roles:
- name: jhampson_dbre.home_assistant.install_hacs
```
License
-------
MIT
Author Information
------------------
@jhampson-dbre
3 changes: 3 additions & 0 deletions roles/install_hacs/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
ha_path: /usr/share/hassio/homeassistant
install_hacs_requirements: true
37 changes: 37 additions & 0 deletions roles/install_hacs/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
galaxy_info:
author: Jared Hampson
description: Install Home Assistant Community Store in Home Assistant Supervised

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
license: MIT

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: Debian
versions:
- buster

galaxy_tags:
- home
- assistant
- supervised
- raspberry
- pi
- hassio
- hacs

dependencies: []
33 changes: 33 additions & 0 deletions roles/install_hacs/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
- name: Install install_hacs role requirements
import_tasks: requirements.yml
when: install_hacs_requirements|bool

- name: Create custom_components directory
file:
path: "{{ ha_path }}/custom_components"
state: directory
mode: '0755'

- name: Clean up existing HACS directory
file:
path: "{{ ha_path }}/custom_components/hacs"
state: absent

- name: Create HACS directory
file:
path: "{{ ha_path }}/custom_components/hacs"
state: directory
mode: '0755'

- name: Download and unpack HACS
unarchive:
src: https://github.com/hacs/integration/releases/latest/download/hacs.zip
dest: "{{ ha_path }}/custom_components/hacs"
remote_src: yes

- name: Restart Home Assistant
shell: |
ha core restart
args:
warn: no # noqa 301
7 changes: 7 additions & 0 deletions roles/install_hacs/tasks/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Install OS package prereqs # noqa 403
apt:
name:
- unzip
state: present
update_cache: yes
2 changes: 2 additions & 0 deletions roles/install_hacs/tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions roles/install_hacs/tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- install_hacs

0 comments on commit 010877f

Please sign in to comment.