diff --git a/functions b/functions index 900377e4f72486f6699ecf736f96adfbc04e92da..e8a049414bca2b14b158444dac1b94c2ca90d9be 160000 --- a/functions +++ b/functions @@ -1 +1 @@ -Subproject commit 900377e4f72486f6699ecf736f96adfbc04e92da +Subproject commit e8a049414bca2b14b158444dac1b94c2ca90d9be diff --git a/intern/docker_homeassistant/tasks/main.yml b/intern/docker_homeassistant/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..ec625b05a6d2a61e1c840f139720f17dce3717b4 --- /dev/null +++ b/intern/docker_homeassistant/tasks/main.yml @@ -0,0 +1,42 @@ +--- + +- include: ../functions/get_secret.yml + with_items: + - { path: "{{ basedir }}/homeassistant_admin_password", length: 12 } + - { path: "{{ basedir }}/influxdb_password", length: 12 } + - { path: "{{ basedir }}/influxdb_token", length: 32 } + + +- name: "create folder struct for {{ basedir }}" + file: + path: "{{ item }}" + state: "directory" + with_items: + - "{{ basedir }}" + - "{{ basedir }}/config/" + + +- name: "copy config files for {{ basedir }}" + template: + src: "{{ item }}" + dest: "{{ basedir }}/{{ item }}" + with_items: + - docker-compose.yml + - config/automations.yaml + - config/configuration.yaml + - config/scenes.yaml + - config/scripts.yaml + register: config_files + + +- name: "stop {{ servicename }} docker" + docker_compose: + project_src: "{{ basedir }}" + state: absent + when: config_files.changed + + +- name: "start {{ servicename }} docker" + docker_compose: + project_src: "{{ basedir }}" + state: present diff --git a/intern/docker_homeassistant/templates/config/automations.yaml b/intern/docker_homeassistant/templates/config/automations.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/intern/docker_homeassistant/templates/config/configuration.yaml b/intern/docker_homeassistant/templates/config/configuration.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e30d80715d5041b3d06d02c76d0df5f662da6912 --- /dev/null +++ b/intern/docker_homeassistant/templates/config/configuration.yaml @@ -0,0 +1,55 @@ + +# Loads default set of integrations. Do not remove. +default_config: + +# includes +automation: !include automations.yaml +script: !include scripts.yaml +scene: !include scenes.yaml + +# Load frontend themes from the themes folder +frontend: + themes: !include_dir_merge_named themes + +# https://www.home-assistant.io/docs/configuration/basic/ +homeassistant: + name: "warpzone" + latitude: 51.944514 + longitude: 7.638933 + elevation: 70 + unit_system: metric + currency: EUR + country: DE + time_zone: Europe/Berlin + internal_url: https://{{ domain }} + auth_providers: + - type: trusted_networks + trusted_networks: + - 10.0.0.0/22 + allow_bypass_login: true + - type: homeassistant + +# https://www.home-assistant.io/integrations/http/ +http: + server_port: 8123 + ip_ban_enabled: False + login_attempts_threshold: 10 + use_x_forwarded_for: true + trusted_proxies: + - 172.0.0.0/8 + +# https://www.home-assistant.io/integrations/logger +# log_level= critical, fatal, error, warning, warn, info, debug, notset +logger: + default: info + +# https://www.home-assistant.io/integrations/influxdb/ +influxdb: + api_version: 2 + host: influxdb + port: 8086 + ssl: false + organization: homeassistant + bucket: homeassistant + token: {{ influxdb_token }} + default_measurement: units diff --git a/intern/docker_homeassistant/templates/config/scenes.yaml b/intern/docker_homeassistant/templates/config/scenes.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/intern/docker_homeassistant/templates/config/scripts.yaml b/intern/docker_homeassistant/templates/config/scripts.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/intern/docker_homeassistant/templates/docker-compose.yml b/intern/docker_homeassistant/templates/docker-compose.yml new file mode 100644 index 0000000000000000000000000000000000000000..0f41622700e054d2d7da6e9801b690bb5536a499 --- /dev/null +++ b/intern/docker_homeassistant/templates/docker-compose.yml @@ -0,0 +1,46 @@ + +version: "3" + +services: + + app: + + image: homeassistant/home-assistant:2023.1 + restart: always + volumes: + - "/etc/localtime:/etc/localtime:ro" + - "{{ basedir }}/config:/config" + environment: + TZ: "Europe/Berlin" + labels: + - traefik.enable=true + - traefik.http.routers.{{ servicename }}.rule=Host(`{{ domain }}`) + - traefik.http.routers.{{ servicename }}.entrypoints=websecure + - traefik.http.services.{{ servicename }}.loadbalancer.server.port=8123 + networks: + - default + - web + + + influxdb: + + image: influxdb:2.6.0 + restart: always + ports: + - {{ int_ip4 }}:{{ influxdb_port }}:8086 + volumes: + - "{{ basedir }}/influxdb:/var/lib/influxdb2" + environment: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: homeassistant + DOCKER_INFLUXDB_INIT_PASSWORD: {{ influxdb_password }} + DOCKER_INFLUXDB_INIT_ORG: homeassistant + DOCKER_INFLUXDB_INIT_BUCKET: homeassistant + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: {{ influxdb_token }} + networks: + - default + + +networks: + web: + external: true diff --git a/site.yml b/site.yml index 2029d7caece8ac87d1a74adbd5032e62ff12adc5..4ea42d1a04dcc149dbb75a3557774f7cff0a69f9 100644 --- a/site.yml +++ b/site.yml @@ -62,6 +62,13 @@ basedir: /srv/heimdall, domain: "services.warpzone.lan" } + - { + role: intern/docker_homeassistant, tags: homeassistant, + servicename: homeassistant, + basedir: /srv/homeassistant, + domain: "ha.warpzone.lan", + influxdb_port: 38086 + } - { role: intern/docker_mqtt, tags: mqtt, servicename: mqtt,