From f1b459860128f1019532ce6c759741cb75e1cbb5 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 14 Jul 2020 11:35:17 -0500 Subject: [PATCH] roles/hassdb: Deploy Home Assistant database Normally, Home Assistant uses a SQLite database for storing state history. On a Raspberry Pi with only an SD card for storage like *hass1.pyrocufflink.blue*, this can become extremely slow, especially for large data sets. To speed up features like history and logbook, Home Assistant supports using an external database engine such as PostgreSQL or MariaDB. The *hassdb* role and corresponding `hassdb.yml` playbook deploys a PostgreSQL server for Home Assistant to use. It needs only to create the role and database, as Home Assistant manages its own schema. --- hassdb.yml | 5 +++++ hosts | 2 ++ roles/hassdb/tasks/main.yml | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 hassdb.yml create mode 100644 roles/hassdb/tasks/main.yml diff --git a/hassdb.yml b/hassdb.yml new file mode 100644 index 0000000..4fa906b --- /dev/null +++ b/hassdb.yml @@ -0,0 +1,5 @@ +- hosts: hassdb + vars_files: + - vault/hassdb/{{ inventory_hostname }} + roles: + - hassdb diff --git a/hosts b/hosts index a62031f..ac1951b 100644 --- a/hosts +++ b/hosts @@ -40,6 +40,8 @@ file0.pyrocufflink.blue [gitea] git0.pyrocufflink.blue +[hassdb] + [home-assistant] hass1.pyrocufflink.blue diff --git a/roles/hassdb/tasks/main.yml b/roles/hassdb/tasks/main.yml new file mode 100644 index 0000000..d6e19e8 --- /dev/null +++ b/roles/hassdb/tasks/main.yml @@ -0,0 +1,21 @@ +- name: ensure psycopg2 is installed + package: + name: python-psycopg2 + state: present + tags: install + +- name: ensure homeassistant postgresql user exists + become: true + become_user: postgres + postgresql_user: + name: homeassistant + password: '{{ hassdb_password }}' + tags: pg-user + +- name: ensure homeassistant postgresql database exists + become: true + become_user: postgres + postgresql_db: + name: homeassistant + owner: homeassistant + tags: pg-db