From 93b4bef05d993b7f22942c70f7eca5a18d572477 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 27 Jun 2020 16:16:52 +0100 Subject: [PATCH] Add home-assistant --- ansible/main.yml | 1 + .../home-assistant/files/configuration.yml | 15 +++++++ .../home-assistant/files/docker-compose.yml | 17 +++++++ ansible/roles/home-assistant/tasks/main.yml | 45 +++++++++++++++++++ terraform/jakehoward.tech.tf | 8 ++++ 5 files changed, 86 insertions(+) create mode 100644 ansible/roles/home-assistant/files/configuration.yml create mode 100644 ansible/roles/home-assistant/files/docker-compose.yml create mode 100644 ansible/roles/home-assistant/tasks/main.yml diff --git a/ansible/main.yml b/ansible/main.yml index 1eceb2e..2408d01 100644 --- a/ansible/main.yml +++ b/ansible/main.yml @@ -29,6 +29,7 @@ - hosts: intersect roles: - netdata + - home-assistant - intersect-docker - hosts: grimes diff --git a/ansible/roles/home-assistant/files/configuration.yml b/ansible/roles/home-assistant/files/configuration.yml new file mode 100644 index 0000000..2c74ee6 --- /dev/null +++ b/ansible/roles/home-assistant/files/configuration.yml @@ -0,0 +1,15 @@ +# Configure a default setup of Home Assistant (frontend, api, etc) +default_config: + +# Text to speech +tts: + - platform: google_translate + +group: !include groups.yaml +automation: !include automations.yaml +script: !include scripts.yaml +scene: !include scenes.yaml + +homeassistant: + auth_mfa_modules: + - type: totp diff --git a/ansible/roles/home-assistant/files/docker-compose.yml b/ansible/roles/home-assistant/files/docker-compose.yml new file mode 100644 index 0000000..276670c --- /dev/null +++ b/ansible/roles/home-assistant/files/docker-compose.yml @@ -0,0 +1,17 @@ +version: "2.3" + +services: + homeassistant: + image: homeassistant/home-assistant:stable + container_name: home-assistant + network_mode: host + volumes: + - ./config:/config + environment: + - TZ=Europe/London + restart: unless-stopped + labels: + - traefik.enable=true + - traefik.http.routers.homeassistant.rule=Host(`homeassistant.jakehoward.tech`) + - traefik.http.routers.homeassistant.tls.certresolver=le + - traefik.http.services.home-assistant-homeassistant.loadbalancer.server.port=8123 diff --git a/ansible/roles/home-assistant/tasks/main.yml b/ansible/roles/home-assistant/tasks/main.yml new file mode 100644 index 0000000..122cbe5 --- /dev/null +++ b/ansible/roles/home-assistant/tasks/main.yml @@ -0,0 +1,45 @@ +- name: Create home-assistant directory + file: + path: /opt/home-assistant + state: directory + owner: "{{ docker_user.name }}" + mode: "{{ docker_compose_directory_mask }}" + become: true + +- name: Create config directory + file: + path: /opt/home-assistant/config + state: directory + mode: "{{ docker_compose_directory_mask }}" + become: true + +- name: Install home-assistant compose file + template: + src: files/docker-compose.yml + dest: /opt/home-assistant/docker-compose.yml + mode: "{{ docker_compose_file_mask }}" + owner: "{{ docker_user.name }}" + validate: /usr/bin/docker-compose -f %s config + register: compose_file + become: true + +- name: Install config + template: + src: files/configuration.yml + dest: /opt/home-assistant/config/configuration.yaml + mode: "{{ docker_compose_file_mask }}" + owner: "{{ docker_user.name }}" + register: config_file + become: true + +- name: Cycle home-assistant container + docker_compose: + project_src: /opt/home-assistant + pull: true + remove_orphans: true + remove_volumes: true + state: "{{ item }}" + when: compose_file.changed or config_file.changed + loop: + - absent + - present diff --git a/terraform/jakehoward.tech.tf b/terraform/jakehoward.tech.tf index 59b6bc9..aefa593 100644 --- a/terraform/jakehoward.tech.tf +++ b/terraform/jakehoward.tech.tf @@ -131,3 +131,11 @@ resource "cloudflare_record" "jakehowardtech_calibre" { type = "A" ttl = 1 } + +resource "cloudflare_record" "jakehowardtech_homeassistant" { + zone_id = cloudflare_zone.jakehowardtech.id + name = "homeassistant" + value = vultr_server.casey.main_ip + type = "A" + ttl = 1 +}