From 3b8cc7d1ea5b122b850d4f9942e542a40cf3643a Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Wed, 2 Oct 2024 22:09:54 +0200 Subject: [PATCH] homeassistant: Prepare system for installation (install packages, create directories) --- roles/homeassistant/defaults/main.yml | 10 ++++++ roles/homeassistant/tasks/main.yml | 5 +++ roles/homeassistant/tasks/preparation.yml | 41 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 roles/homeassistant/tasks/preparation.yml diff --git a/roles/homeassistant/defaults/main.yml b/roles/homeassistant/defaults/main.yml index 11d0f72..8565fda 100644 --- a/roles/homeassistant/defaults/main.yml +++ b/roles/homeassistant/defaults/main.yml @@ -1,3 +1,13 @@ --- +# Python version required for home assistant ha_python_version: '3.12' + +# The location of the config directory +ha_conf_dir: /etc/homeassistant + +# The location of the installatin directory +ha_venv_dir: "/opt/homeassistant" + +# The default user +ha_user: homeassistant diff --git a/roles/homeassistant/tasks/main.yml b/roles/homeassistant/tasks/main.yml index 87982b2..bd2e656 100644 --- a/roles/homeassistant/tasks/main.yml +++ b/roles/homeassistant/tasks/main.yml @@ -3,3 +3,8 @@ - name: Install python if required ansible.builtin.include_tasks: python_312.yml when: ha_python_version == '3.12' + +- name: Include sub-tasks + ansible.builtin.include_tasks: '{{ item }}' + loop: + - preparation.yml diff --git a/roles/homeassistant/tasks/preparation.yml b/roles/homeassistant/tasks/preparation.yml new file mode 100644 index 0000000..1c74213 --- /dev/null +++ b/roles/homeassistant/tasks/preparation.yml @@ -0,0 +1,41 @@ +--- + +- name: Install commonly-named packages + ansible.builtin.package: + name: "{{ item }}" + state: present + loop: + - python3 + - python3-dev + - python3-venv + - python3-pip + - libffi-dev + - libssl-dev + - libjpeg-dev + - zlib1g-dev + - autoconf + - build-essential + - libopenjp2-7 + - libtiff6 + - libturbojpeg0 + - tzdata + - git + - ffmpeg + +- name: Create user + ansible.builtin.user: + name: "{{ ha_user }}" + comment: "Home Assistant" + system: true + shell: "/sbin/nologin" + +- name: Create directory + ansible.builtin.file: + path: "{{ item }}" + state: directory + mode: "02775" + owner: "{{ ha_user }}" + group: "{{ ha_user }}" + loop: + - "{{ ha_conf_dir }}" + - "{{ ha_venv_dir }}"